简体   繁体   English

类型错误:无法读取未定义的属性“角色”|| Discord.js

[英]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.

相关问题 Discord.JS:TypeError:无法读取未定义的属性“角色” - Discord.JS:TypeError: Cannot read property 'roles' of undefined Discord.JS TypeError:尝试添加角色时无法读取未定义的属性“角色” - Discord.JS TypeError: Cannot read property 'roles' of undefined while trying to add roles discord.js Linkfilter TypeError:无法读取 null 的属性“角色” - discord.js Linkfilter TypeError: Cannot read property 'roles' of null Discord.js:Linkblocker TypeError:无法读取 null 的属性“角色” - Discord.js: Linkblocker TypeError: Cannot read property 'roles' of null discord.js - 无法读取未定义的属性“角色” - discord.js - Cannot read property 'roles' of undefined 无法读取未定义的属性“角色”| 不和谐.js | javascript - Cannot read property 'roles' of undefined | discord.js | javascript 类型错误:无法读取未定义 Discord.js javascript 的属性“添加” - TypeError: Cannot read property 'add' of undefined Discord.js javascript 类型错误:无法读取未定义的属性 'has' // Discord.js - TypeError: Cannot read property 'has' of undefined // Discord.js 遇到 TypeError:无法读取 Discord.JS 中未定义的属性“0” - Encountering TypeError: Cannot read property '0' of undefined in Discord.JS Discord.JS UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性“startsWith” - Discord.JS UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'startsWith' of undefined
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM