TypeError:无法读取未定义的属性(读取' haspermission')
我又回来了我的票务功能。这次,我正在处理一个近距离命令。无论我尝试什么,我总是会遇到相同的错误:
TypeError: message.member.hasPermission is not a function
任何可以查看代码的人?
const { MessageEmbed, Collection, Permissions } = require ('discord.js');
module.exports = {
name: 'close',
description: "closes the ticket",
execute(message, args, client){
if(!message.member.hasPermission("MANAGE_CHANNELS")) return message.channel.send("Only a moderator can end a ticket!")
if(message.member.hasPermission("MANAGE_CHANNELS")) message.channel.delete()
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
首先,您应该尝试阅读 docs 属性guildmember实际上具有什么,只需快速查看它,您应该能够找到
.permissions
,然后从中,您将获得此 .has 函数。因此,您的最终代码应该是Firstly, you should try reading the docs and see what properties GuildMember actually has, just a quick look through it, you should be able to find a
.permissions
, following from that, you'll get to this doc on the Permissions class. From there, you can see you can use the.has
function. So your final code should be此代码将检查成员是否已许可
Manage_Channels
,并且由于.permissions.has()
返回布尔值,如果用户do no no no no no no no n dre boolean拥有这样的权限,它将返回一条消息,即他们无法使用命令,否则它将删除频道...this code will check if the member has the permission to
MANAGE_CHANNELS
and since.permissions.has()
returns a boolean, it will either return true or false, if the user doesn't have such permission it will return a message that they cannot use the command, else if it will delete the channel...按照您对我的评论的回答,看来您只是将论点放在错误的顺序中。
您的功能被定义为,
因此您应该按照相同的顺序将其称为参数:
按照您对此答案的评论,它解决了初始问题。现在
message.member
具有一个值!但是现在
member.haspermission
似乎不是一个函数。确实不是:当您查看 a>,公会上没有haspermission
方法。因此,您必须弄清楚确切需要什么并查看文档以了解如何做。
Following your answer to my comment, it seems that you just put the arguments in the wrong order.
Your function is defined as
So you should call it with the arguments in the same order:
Following your comment on this answer, it fixed the initial issue. Now
message.member
has a value!But now
member.hasPermission
does not seem to be a function. And indeed it is not: when you look at the documentation, there is nohasPermission
method on a GuildMember.So you have to figure out what exactly you need and look at the documentation to understand how to do it.