简体   繁体   中英

Role permission for bot command

Do i have to define something or something else? I saw that thing with the role permission somewhere online.

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.);
          }
    }

they changed it to message.member.roles.cache, also you can use find instead (prob better performance wise, and if not it would be equal, and in that case it still has the pro of better readability),

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM