简体   繁体   English

Discord.js:TypeError:无法读取未定义的属性(读取“has”)

[英]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 文档,并查看可用的属性,它同时具有idpermissions

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.

相关问题 Discord.js:TypeError:无法读取未定义的属性(读取“添加”) - Discord.js: TypeError: Cannot read properties of undefined (reading 'add') 类型错误:无法读取未定义的属性(读取“createdTimestamp”)discord.js - TypeError: Cannot read properties of undefined (reading 'createdTimestamp') discord.js 类型错误:无法读取 discord.js 中未定义的属性(读取“发送”) - TypeError: Cannot read properties of undefined (reading 'send') in discord.js Discord.js - TypeError:无法读取未定义的属性(读取“设置”) - Discord.js - TypeError: Cannot read properties of undefined (reading 'set') TypeError:无法读取未定义的属性(读取“设置”)Discord.js - TypeError: Cannot read properties of undefined (reading 'set') Discord.js 类型错误:无法读取未定义的属性(读取“缓存”)(discord.js) - TypeError: Cannot read properties of undefined (reading 'cache') (discord.js) discord.js v13 permissions.has() function 不工作(TypeError: Cannot read properties of undefined (reading 'has')) - discord.js v13 permissions.has() function not working (TypeError: Cannot read properties of undefined (reading 'has')) Discord.js:类型错误:无法读取 null 的属性(读取“状态”) - Discord.js: TypeError: Cannot read properties of null (reading 'status') TypeError:无法在 discord.js v13 中读取未定义的属性(读取“路径”) - TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13 discord.js v13 - 类型错误:无法读取未定义的属性(读取“正常运行时间”) - discord.js v13 - TypeError: Cannot read properties of undefined (reading 'uptime')
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM