我试图使一个禁令命令,可以禁止使用他的ID的人,它的工作很好,问题是,当我试图禁止一个用户不是在服务器上(使用他的ID)或只使用1个数字,命令不起作用,机器人崩溃。我认为问题是由if语句引起的,但我不确定。
下面是我的代码:
let args = messageArray.slice(1);
if(message.content.startsWith(prefix + 'ban')) {
let toBan = message.guild.members.cache.get(args[0]) || message.mentions.members.first() || message.guild.members.cache.find(x => x.user.username.toLowerCase() === args.slice(0).join(" ") || x.user.username === args[0]);
if(!args) return message.channel.send('You need to mention a user!')
if (!message.member.hasPermission("VIEW_AUDIT_LOG")) return message.channel.send("You don't have enough permissions.")
if (!message.guild.me.hasPermission("BAN_MEMBERS")) return message.channel.send("I don't have enought permissions.")
if(!toBan.bannable) return message.channel.send("I can't ban that user!")
if(toBan === message.author) return message.channel.send("No.")
if(toBan.roles.highest.position >= message.member.roles.highest.position) return message.channel.send("You can't ban anyone that have a high or same role that you have.")
const reason = args[1] || "Undefined";
member.ban(`${toBan}`, {
reason: reason
})
message.channel.send(`${toBan} Has been banned of the server by ${message.author}!`)
}
您可以使用GuildMemberManager.ban()
,这需要UserResolvable
。可以是User
,GuildMember
,甚至是Snowflake
(ID)。
简单的例子:
message.guild.members.ban("12345678901234567");