简体   繁体   English

无法读取 Discord.js 上未定义的属性“hasPermission”

[英]Cannot read property 'hasPermission' of undefined on Discord.js

this is my code:这是我的代码:

if(!member.guild.me.hasPermission('SEND_MESSAGES')) return;

according to discord.js.org's documention it's fine, and up till now anyone i asked didn't know the answer, what's the problem...根据 discord.js.org 的文档,这很好,直到现在我问的任何人都不知道答案,有什么问题...

From the documentation , yes, me is a property of guild, but it can be undefined .文档来看,是的,我是公会的一个属性,但它可以是undefined

.me .me

The client user as a GuildMember of this guild客户端用户作为该公会的 GuildMember

Type: ?GuildMember类型:?公会会员

From the code ,代码

get me() {
    return this.members.get(this.client.user.id);
}

If this.client.user.id is undefined, or not in the guild , you will get undefined returned and therefore, no property hasPermission .如果this.client.user.id未定义,或者不在guild ,您将得到 undefined 返回,因此没有属性hasPermission The easiest way to figure out would be debugging .最简单的方法是调试

Whatever me is it's undefined .无论me是什么,它都是undefined Use your debugger to trace your code, find out why it's not being set to what you expect.使用您的调试器来跟踪您的代码,找出它没有被设置为您期望的原因。

You just need to add the command你只需要添加命令

if (!message.guild) return;

to the code到代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Discord.js (v12) 赠品命令 --> 错误:无法读取未定义的属性“hasPermission” - Discord.js (v12) Giveaway Command --> Error: Cannot read property 'hasPermission' of undefined discord.js | 无法读取未定义的属性“设置” - discord.js | Cannot read property 'set' of undefined 类型错误:无法读取未定义 Discord.js javascript 的属性“添加” - TypeError: Cannot read property 'add' of undefined Discord.js javascript 无法读取未定义的 discord.js 警告命令的属性“发送” - Cannot read property 'send' of undefined discord.js warn command discord.js 无法读取未定义的属性“第一个” - discord.js Cannot read property 'first' of undefined 如何解决discord.js中的“无法读取未定义的属性'反应'” - How to fix “Cannot read property 'react' of undefined” in discord.js Discord.js 的欢迎消息 - “无法读取未定义的属性 'get'” - Welcome message with Discord.js - “Cannot read property 'get' of undefined” 类型错误:无法读取未定义的属性 '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