Reputation: 15
I'm trying to make a command that gives a user a role. It was working before, but not it just gives the bot a role.
module.exports = {
name: "addevent",
description: "Add the event ping role to a user",
async run(client, message, args) {
const { member } = message;
if (message.member.roles.cache.has('793222158981529621')) {
const { member } = message;
message.channel.send(`${member} You already have this role.`)
}
if (message.channel.id !== '793224633759432755') return;
member.roles.add('793222158981529621')
message.channel.send(`${member} Added the event ping role.`)
}
}
This is also happening to my level command that's supposed to check a user's level. It checks the bot's level, not the user's.
Upvotes: 0
Views: 44
Reputation: 1247
let role = message.guild.roles.cache.find(r => r.name === "Role Name Here");
if (message.channel.id !== 'Channel ID Here') return;
if (message.member.roles.cache.has(role.id)) {
return message.channel.send(`${message.member} You already have this role.`)
}
message.member.roles.add(role);
message.channel.send(`${message.member} Added the event ping role.`);
My example has a variable called role
which finds the role by its name, so you have to provide the name of the role there. Your if-statement with the message.channel.id
was understandable and is a nice way to get the role in only one channel. The second if-statement just asks if a user already has that role (dont forget: in .has()
you have to provide an ID, in this case it is easily done with role.id
). Anyways if the user has that role it will send a message and return. Otherwise it will add the role to the user and also send a message.
Upvotes: 1