好的,所以我确保检查ID, 试图取消禁止的用户被禁止。 ID是正确的 我试图控制台记录userBanned返回什么,并且它是未定义的 怎么样?
const text = args.join(` `)
const bansCollection = await message.guild.fetchBans()
const userBanned = bansCollection.find(user => user.id == text)
if (!isNaN(text)) {
if (userBanned) {
await message.guild.members.unban(text)
message.channel.send(`<@${text}> has been unbanned`)
} else { message.channel.send(new Discord.MessageEmbed().setTitle(`**That user is not Banned!**`)) }
} else { message.channel.send(`You Need the user's ID!`) }
console.log(text , bansCollection, userBanned)}
答案 0 :(得分:0)
我将获取审核日志并对其进行过滤。
示例:
message.guild.fetchAuditLogs()
.then(logs => {
let ban = logs.entries.filter(e => e.action === 'MEMBER_BAN_ADD') //get all the bans
ban = ban.filter(e => e.target.id === text) //filter the bans from the user
if (!message.guild.members.cache.get(text)) return message.channel.send(`This user is not in this server.`);
if (userBanned) {
await message.guild.members.unban(text)
message.channel.send(`<@${text}> has been unbanned`);
} else {
let embed = new Discord.MessageEmbed();
embed.setTitle(`**That user is not Banned!**`);
message.channel.send(embed);
}
});