[英]TypeError: Cannot read property 'roles' of undefined || Discord.js
I'm trying to make a mute command for my discord bot but when I run:我正在尝试为我的 discord 机器人发出静音命令,但是当我运行时:
let mutedRole = message.guild.roles.cache.find(r => r.name === 'Muted');
I get an error in the console saying:我在控制台中收到错误消息:
TypeError: Cannot read property 'roles' of undefined
as if message.guild
is undefined, the command works but I get this error in the console.好像message.guild
未定义,该命令有效,但我在控制台中收到此错误。 If anyone knows how to get rid of this error any help is appreciated.如果有人知道如何摆脱此错误,我们将不胜感激。
lmao I finally found the issue and it was something completely unrelated to the mute command, when the mute command is executed it dm's the user that they have been muted and that calls the client.on("channelCreate"), which I was not checking for if it was dm's so it was trying to get the guild.roles attribute of a dm. lmao我终于找到了问题,它与静音命令完全无关,当执行静音命令时,dm是用户他们已被静音并调用client.on(“channelCreate”),我没有检查因为如果它是 dm 的,那么它试图获取 dm 的 guild.roles 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.