[英]Cannot read properties of undefined (reading 'user')
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)
}
我正在努力做到这一点,以便当用户未被禁止时,它将返回一个简单的嵌入,但似乎也一直返回Cannot read properties of undefined (reading 'user')
您可以尝试使用.find()
吗?
const checkTheUserStated = getGuildBanList.find(user => user.id === unbanUserId.id);
console.log 或尝试一下,让我知道它是否适合你
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.