我是一个初学者不和谐机器人创建者,(实际上是我的第一个机器人)所以这可能是一个愚蠢的问题,但我只是不知道如何让你不能踢/禁止任何具有“管理员”角色的人。到目前为止我的代码:
const { MessageManager } = require("discord.js");
module.exports = {
name: "kick",
description: "This command kicks a member!",
execute(message, args) {
const target = message.mentions.users.first();
if (target) {
const memberTarget = message.guild.members.cache.get(target.id);
if (!message.member.roles.cache.has("845966863070789644") && !message.member.guild.me.hasPermission("ADMINISTRATOR")) {
message.channel.send(`You can't kick mods`);
} else {
memberTarget.kick();
message.channel.send("Sure. See you later.");
}
} else {
message.channel.send(`I was unable to execute that command -.-`);
}
},
};
答案 0 :(得分:2)
在告诉用户他们不能踢模组之前,您正在检查它们是否不是模组。因此,您可以仅踢模组。另外,不要检查 ADMINISTRATOR 和角色,只需检查 ADMINISTRATOR 权限,因为它更简单,否则做起来很麻烦。这里有一个更正(注意,我还没有测试过这段代码,但我以前用过类似的代码):
const { MessageManager } = require("discord.js");
module.exports = {
name: "kick",
description: "This command kicks a member!",
execute(message, args) {
const target = message.mentions.users.first();
if (target) {
const memberTarget = message.guild.members.cache.get(target.id);
if (message.member.guild.me.hasPermission("ADMINISTRATOR")) {
message.channel.send(`You can't kick mods`);
} else {
memberTarget.kick();
message.channel.send("Sure. See you later.");
}
} else {
message.channel.send(`I was unable to execute that command -.-`);
}
},
};
答案 1 :(得分:1)
这应该会停止踢具有管理员权限的成员的能力。对于角色,将 memberTarget.hasPermission("ADMINISTRATOR")
替换为 memberTarget.roles.caches.find(i => i.name.toUpperCase() === "ADMINISTRATOR")
module.exports = {
name: "kick",
description: "This command kicks a member!",
execute(message, args) {
const target = message.mentions.users.first();
if (target) {
const memberTarget = message.guild.members.cache.get(target.id);
if (memberTarget.hasPermission("ADMINISTRATOR")) {
message.channel.send(`You can't kick mods`);
} else {
memberTarget.kick();
message.channel.send("Sure. See you later.");
}
} else {
message.channel.send(`I was unable to execute that command -.-`);
}
},
};