[英]Discord.js: TypeError: Cannot read properties of undefined (reading 'has')
I am creating a Discord music bot using discord.js version 13.6.0 and discord-player but I keep getting this error, here is my code:我正在使用 discord.js 版本 13.6.0 和 discord-player 创建一个 Discord 音乐机器人,但我一直收到此错误,这是我的代码:
const { MessageEmbed, Permissions } = require('discord.js');
module.exports = {
name: 'stop',
aliases: [],
utilisation: '{prefix}stop',
voiceChannel: true,
execute(client, message) {
if (message.member.id.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) {
// Stop the player
};
},
};
The error I get when running that command:运行该命令时出现的错误:
if(message.member.id.permissions.has(Permissions.FLAGS.KICK_MEBERS)){
TypeError: Cannot read properties of undefined (reading 'has')
类型错误:无法读取未定义的属性(读取“有”)
I don't know why this is happening, please could someone help me?我不知道为什么会这样,请有人帮助我吗?
You are trying to read permissions from the member.id
.您正在尝试从
member.id
读取权限。
If you take a look at the DiscordJS Documentation for member , and look at the available properties, it has both id
and permissions
.如果您查看member 的 DiscordJS 文档,并查看可用的属性,它同时具有
id
和permissions
。
So, changing your line to message.member.permissions.has(Permissions.FLAGS.KICK_MEBERS)
instead of message.member.id.permissions.has(Permissions.FLAGS.KICK_MEBERS)
should fix this for you.因此,将您的行更改为
message.member.permissions.has(Permissions.FLAGS.KICK_MEBERS)
而不是message.member.id.permissions.has(Permissions.FLAGS.KICK_MEBERS)
应该可以为您解决此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.