检查某人是否与Discord.js有关

时间:2020-06-03 08:30:00

标签: javascript node.js discord discord.js

我正在尝试使用discord.js创建一个discord机器人,但是遇到了这个错误。 我知道还有其他有关此的文章,但是我无法使它正常工作。 在运行命令之前,我需要检查用户是否具有管理员/ mod角色。

        case 'clear':
        if(!author.roles.cache.has('686001018277855308'))  return msg.reply('you dont have the permissions to do this.');
        else if(author.roles.cache.has('686001018277855308')){

            if(!args[1]) return msg.reply('please add the number of messages to clear in the command');
            else{
                msg.channel.bulkDelete(args[1]);
                msg.reply(args[1] + ' messages cleared!');
            }
        }

    break;

我无法使它正常工作。我收到以下错误:

C:\ Program Files \ nodejs \ node.exe index.js froggo在线! c:\ Users \ frenc \ OneDrive \ Documents \ GitHub \ froggobot \ index.js:53 if(!author.roles.cache.has('686001018277855308'))返回msg.reply('您无权执行此操作。'); ^

TypeError:无法读取未定义的属性“缓存”

如果您需要任何其他信息,请在评论中提问。

还有一个问题,是否可以将该过程保存为单个命令并在其他文件中使用它而无需重新键入整个内容?

1 个答案:

答案 0 :(得分:0)

我的建议是,您只是尝试检查用户是否可以通过权限检查来删除其他人发送的邮件。

这就是我要做的:

case 'clear':
    if(!msg.member.permissions.has('MANAGE_MESSAGES')) return msg.reply('you dont have the permissions to do this.');
    if(!args[1]) return msg.reply('please add the number of messages to clear in the command');

    msg.channel.bulkDelete(args[1]);
    msg.reply(args[1] + ' messages cleared!');
break;