机器人命令的权限

问题描述 投票:0回答:1

我是否必须定义其他内容?我在网上某处看到具有角色许可的东西。

message.member.roles.some is not a function

execute(message, args) {
        if(message.member.roles.some(role => role.name === 'Community Manager')) {
            if (!args.length) return message.channel.send(You didn't pass any command to reload, ${message.author}!);
            const commandName = args[0].toLowerCase();
            const command = message.client.commands.get(commandName)
                || message.client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName));

            if (!command) return message.channel.send(There is no command with that name or alias `${commandName}`, ${message.author}!);    

            delete require.cache[require.resolve(./${command.name}.js)];

            try {
                const newCommand = require(./${command.name}.js);
                message.client.commands.set(newCommand.name, newCommand);
                message.channel.send(Command `${command.name}` was reloaded!);
            } catch (error) {
                console.log(error);
                message.channel.send(There was an error while reloading a command `${command.name}`:\n`${error.message}`);
            }
        }else{
            message.channel.send(You don't have the permission to execute that command.);
          }
    }
javascript permissions bots discord.js roles
1个回答
1
投票

他们将其更改为message.member.roles.cache,也可以使用find代替(在性能上可能会有更好的表现,如果不相等,那么它仍然具有更好的可读性),

messsage.member.roles.cache.find(r => r.name === "Community Manager");

© www.soinside.com 2019 - 2024. All rights reserved.