我正在尝试建立某种踢腿系统。我想知道如何得到文字中提到的名字。
client.on("message", (message) => {
if (message.member.hasPermission(["KICK_MEMBERS"],["BAN_MEMBERS"])){
if(message.content == "!kick"){
let member = message.mentions.members();
console.log(member)
member.kick("You have been kicked").then ((member) => {
message.channel.send( member.displayName + " has been Kicked!");
})
}
}
});
我知道没有抛出任何错误。
答案 0 :(得分:1)
首先,如果要检查GuildMember.hasPermission()
中的多个权限,则需要传递一个数组。现在编写代码的方式是,传递一个以"KICK_MEMBERS"
作为检查权限的数组,以及一个以"BAN_MEMBERS"
作为explicit
参数的数组。
解决方案: message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMEBRS"])
第二,您将member
声明为集合,而该集合应为GuildMember。
解决方案: const member = message.mentions.members.first()
client.on("message", async message => {
if (message.content === "!kick" && message.member.hasPermission(["KICK_MEMBERS", "BAN_MEMBERS"])) {
try {
const member = message.mentions.members.first();
if (!member) return await message.channel.send(`No user mentioned.`);
await member.kick(`Kicked by ${message.author.tag}`);
await message.channel.send(`${member.user.tag} has been kicked.`);
} catch(err) {
console.error(err);
}
}
});