我当前正在编写一个Discord机器人,但我的临时静音命令遇到了麻烦。我有命令检查服务器中是否有名为“静音”的角色,如果没有,请创建一个新角色并将角色ID添加到我的botconfig.json文件中。
在公会中检查“静音”的代码:
includes
我为上述用户添加角色的代码:
let prefix = botconfig.prefix;
let mutedRole = botconfig.muted;
let muteReason = args.slice(2).join(" ");
let toMute = message.mentions.members.first() || message.guild.members.get(args[0]);
if(!message.guild.roles.find(_role => _role.name == "Muted")) {
message.guild.createRole({
name: "Muted",
color: "#ff0000"
}).then(_mutedRole => {
_mutedRole.setPermissions(['VIEW_CHANNEL', 'READ_MESSAGE_HISTORY', 'CONNECT']);
botconfig.muted = _mutedRole.id;
mutedRole = _mutedRole;
fs.writeFileSync("./botconfig.json", JSON.stringify(botconfig, null, 4));
}).catch(_error => console.log(_error));
}
这会引发错误:
if(message.member.hasPermission(["ADMINISTRATOR", "MANAGE_ROLES", ])) {
if(!toMute || !args[2] || !muteReason) {
return message.reply(`**Please follow this usage:**\n\`${prefix}mute <@user> <length> <reason>\``);
}
if(toMute.roles.has(mutedRole)) { return message.reply("**This user is already muted!**")};
let muteLength = Date.now() + timestring(args[1], "ms");
toMute.addRole(mutedRole);