Reputation: 97
Hi I am following a tutorial on Youtube but I can't figure out why it's not working. Can someone explain to me why it isn't working?
There are no errors in the console but the role doesn't get added
Upvotes: 0
Views: 277
Reputation: 761
Since you're using discord.js^12.x
module, I can still see you use member.removeRoles()
and member.addRoles()
, which are deprecated
. And also, the member
variable you made was a user
property not a guildMember
property. Try to follow the code below:
const Discord = require('discord.js');
const { prefix } = require('../config.json');
module.exports = {
name: 'coloradd',
description: 'Give You Your Color',
execute(message, args, client) {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const colors = message.guild.roles.cache.filter(c => c.name.startsWith('#'))
let str = args.join(' ')
let role = colors.find(role => role.name.slice(1).toLowerCase() === str.toLowerCase());
if (!role) {
return message.channel.send('That color doens\'t exist')
} try {
const member = message.member; // Use `message.member` instead to get the `guldMember` property.
// `addRoles()` and `removeRoles()` are deprecated.
member.roles.remove(colors);
member.roles.add(role);
message.channel.send('Your Have Received Your Color !')
} catch (e) {
let embed = new Discord.MessageEmbed()
.setTitle('Error')
.setColor('RED')
.setDescription('There is an error with the role Hierarchy Or my permissions. Make Sure I am above the color roles')
return (embed)
}
}
}
Visit these guides to help you understand more about the subject:
Upvotes: 2