[英]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
类型:?公会会员
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.