const unbanUserId = interaction.options.getString('user_id')
try {
const getGuildBanList = await interaction.guild.bans.fetch()
const checkTheUserStated = getGuildBanList.get(unbanUserId).user
if (checkTheUserStated) {
await interaction.guild.members.unban(unbanUserId)
const unBannedEmbed = new MessageEmbed()
.setColor('PURPLE')
.setTitle('User unbanned')
.setDescription(`Successfully unbanned <@!${unbanUserId}>`)
return interaction.editReply({ embeds: [unBannedEmbed] })
} else {
const notBanned = new MessageEmbed()
.setColor('PURPLE')
.setDescription(`The stated user is not banned.`)
return interaction.editReply({ embeds: [notBanned] })
}
} catch(e) {
console.log(e)
}
I am trying to make it so that when the user isn't banned that it will return a simple embed but it seem just too keep returning Cannot read properties of undefined (reading 'user')
Can you try using .find()
?
const checkTheUserStated = getGuildBanList.find(user => user.id === unbanUserId.id);
console.log it or try it out, let me know if it works out for you
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.