【发布时间】:2020-09-21 21:17:24
【问题描述】:
我正在尝试使用 discord.js 制作一个不和谐机器人,但我遇到了这个错误。 我知道还有其他关于此的文章,但我无法让它发挥作用。 在运行命令之前,我需要检查用户是否具有 admin/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')) return msg.reply('你没有权限这样做'); ^
TypeError: 无法读取未定义的属性“缓存”
如果您需要任何其他信息,请在 cmets 中询问。
还有一个问题,是否可以将此过程保存为单个命令并在其他文件中使用它而无需重新键入整个内容?
【问题讨论】:
-
在您的情况下,
author.roles未定义。对最后一个问题的回答:是的,这个过程需要保存在其他的地方使用。 -
如果
if(author.roles && ...... -
我看不到整个评论:(你能把它作为答案发布吗?
标签: javascript node.js discord discord.js