好的,我知道那里也有类似的问题,但是不管我尝试什么,我都会得到相同的结果。我已经尝试了2天,以弄清楚如何检查我是否具有ban命令的“ OverBot-Admin”角色。但是,每当我运行命令时,它就会向聊天室发送垃圾邮件!这是我的代码:
if (command === "ban") {
if(message.member.roles.has(role => role.name === "OverBot-Admin")) {
let reason = args.slice(1).join(" ");
if (!reason) reason = "No reason provided";
const user = message.mentions.users.first();
if (user) {
const member = message.guild.member(user);
if (member) {
member
.ban({ reason: "They were being bad." })
.then(() => {
message.reply(
":white_check_mark: Successfully banned " +
message.user.id +
"for " +
reason
);
const embed = new Discord.RichEmbed()
.setTitle("Ban")
.addField("Member:", message.user.id)
.addField("Reason:", reason)
.setTimestamp()
.setFooter(
"Created by OverThrow, OverBot SE",
"https://cdn.discordapp.com/avatars/649431468254429224/0b63291c1e7342c2320ca5c3cce806ca.png?size=2048"
);
})
.catch(err => {
message.reply(":x: I was unable to ban that member!");
console.error(err);
});
} else {
message.reply(":x: That user isn't a member to this guild!");
}
} else {
message.reply(":x: You didn't mention a member to ban!");
}
}
} else {
message.reply(":x: I couldn't ban this user, please make sure you have the OverBot-Admin role!")
}
答案 0 :(得分:0)
message.member.roles.has()
需要角色ID 作为参数,而在这里,您要传入一个函数。我认为您正在寻找的方法是Collection.exists(尽管不建议使用此方法,但是如果有人可以找到其他解决方法,请告诉我)。
在禁止后查看message.reply
函数中的then
,我看到一个message.user.id
。但是,根据文档,message.user
似乎不是消息对象的有效属性。我假设您指的是刚刚被禁止的用户,在这种情况下,您可以重用先前定义的user
或member
变量。
如果您还有其他问题,请随时发表评论。