'Discord JS V13.6.0 issue when I try to create a role
I am trying to add a mute role to a user in a slash commands but it does not work.
Here is my code:
module.exports = {
data: new SlashCommandBuilder()
.setName('mute')
.setDescription('Mute someone')
.addUserOption(option => option.setName("member").setRequired(true).setDescription("Member to mute")),
async execute(interaction) {
if (interaction.member.roles.cache.some(r => r.name === "Admin")) {
const membre = interaction.options.getUser("member");
const guild=interaction.member.guild
const role = await guild.roles.cache.find(role => role.name === "MUTED");;
membre.roles.add(role);
}
else {
await interaction.reply({content: "**YOU DON'T HAVE THE PERMISSIONS !**", ephemeral: true });
}
},
};
Here is my error :
TypeError: Cannot read properties of undefined (reading 'add')
at Object.execute (C:\Users\sunda\Downloads\chabibot-main\commands\mute.js:17:26)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Client.<anonymous> (C:\Users\sunda\Downloads\chabibot-main\index.js:29:3)
Solution 1:[1]
const membre = interaction.options.getUser('member'); // user
const membre = interaction.options.getMember('member'); // member
Role adding is only available on member not user.
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 | Neenhila |
