【发布时间】:2021-10-16 20:04:41
【问题描述】:
我用 discord.js 开发了一个机器人,它使用 msg.member.hasPermission("ADMINISTRATOR") 或 msg.member.roles.cache.has(teacherRoleID) 之类的东西。在我尝试 webhooks 之前一切正常。通过添加这两行:
client.on('ready', () => {
client.user.setStatus("online")
client.user.setActivity("!help", {
type: "PLAYING",
});
superConsole(`Logged in as ${client.user.tag} in ${client.guilds.size} guilds!`);
const hook = new Discord.WebhookClient("ID", "secret token"); // THESE
hook.send("I am now alive!"); // LINES
});
(顺便说一句 superConsole 是一个函数)
从那以后,该程序不再工作并且总是返回相同的错误:(node:20736) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'hasPermission' of null & (node:20736) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'roles' of null
当我删除 webhook 的这两行时,它又可以工作了。为什么?我不明白。
权限和角色的东西在消息监听器中:
client.on('message', async msg => {
if (msg.member.hasPermission('ADMINISTRATOR') {
// some stuff here
}
if (msg.member.roles.cache.has(teacherRoleID) {
// some stuff here
}
});
【问题讨论】:
-
能否请您显示您使用
msg.member.hasPermission("ADMINISTRATOR")和msg.member.roles.cache.has(teacherRoleID)的代码? -
您能否编辑您的帖子以包含该代码?这比尝试使用 cmets 中的代码更新您的问题更容易。
-
我刚刚更新了它
标签: discord discord.js