'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:
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?
Solution 1:[1]
You are trying to read permissions from the 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.
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jnchaba |
