分配角色时Discord.js缺少权限错误

时间:2020-08-30 13:12:04

标签: discord.js

if (message.content.startsWith("_mute")) {
    if (!message.member.hasPermission("ADMINISTRATOR")) {
        return message.reply("You don't have permission to do this.");
    }
    if (message.mentions.users.size === 0) {
        return message.reply("Usage: `_mute [mention]`");
    }

    var muteRole = message.guild.roles.cache.find(r => r.name === "mute");

    if (typeof muteRole === "undefined") {
        return message.reply("Your server doesn't have `mute` role!");
    }

    message.mentions.members.forEach((member) => {
        member.roles.add(muteRole).then((value) => {
            message.reply("Succeed to mute " + member.nickname + ".");
        }).catch((error) => {
            message.reply("Internal bot error");
            console.error(error);
        });
    });
}

尝试为用户分配角色时出现此错误。

我将漫游器的许可号设置为“ 1409286326”

还有什么需要做的吗?

Permission

1 个答案:

答案 0 :(得分:0)

尝试使用以下许可号码:1475677686
可能是因为您缺少一些重要的权限,例如READ_MESSAGES, SEND_MESSAGES和其他权限。另外,您的代码可能需要稍作修改,undefined不是字符串。尝试下面的代码和建议的许可号码:

if (message.content.startsWith("_mute")) {
    if (!message.member.hasPermission("ADMINISTRATOR")) {
        return message.reply("You don't have permission to do this.");
    }
    if (!message.mentions.users.array().length) {
        return message.reply("Usage: `_mute [mention]`");
    }

    var muteRole = message.guild.roles.cache.find(r => r.name === "mute");

    if (!muteRole) {
        return message.reply("Your server doesn't have `mute` role!");
    }

    message.mentions.members.forEach((member) => {
        member.roles.add(muteRole).then((value) => {
            message.reply("Succeed to mute " + member.nickname + ".");
        }).catch((error) => {
            message.reply("Internal bot error");
            console.error(error);
        });
    });
}