I am currently coding a discord bot reaction roles command.
Everything is running smoothly but I have one issue.
When I boot the bot and run the command to create the embed, everything works fine. The issue is when I react to the message it doesn't give me the role. Here is my code:
module.exports = {
name: "reactionrole",
description: "Sets up a reaction role message!",
async execute(message, args, Discord, client) {
const channel = "751217304733351976";
const yellowTeamRole = message.guild.roles.cache.find((role) => role.name === "ROBLOX");
const blueTeamRole = message.guild.roles.cache.find((role) => role.name === "Minecraft");
const redTeamRole = message.guild.roles.cache.find((role) => role.name === "MinecraftBedrock");
const yellowTeamEmoji = "798904223755927562";
const blueTeamEmoji = "798904030553440257";
const redTeamEmoji = "798904121544540181";
let embed = new Discord.MessageEmbed()
.setColor("#e42643")
.setTitle("Choose the games you play!")
.setDescription("Choosing a game will ping you when others want to play with you!\n\n" + `ROBLOX\n` + `Minecraft\n` + "Minecraft Bedrock");
let messageEmbed = await message.channel.send(embed);
messageEmbed.react(yellowTeamEmoji);
messageEmbed.react(blueTeamEmoji);
messageEmbed.react(redTeamEmoji);
client.on("messageReactionAdd", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === yellowTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(yellowTeamRole);
}
if (reaction.emoji.name === blueTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(blueTeamRole);
}
if (reaction.emoji.name === redTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.add(redTeamRole);
} else {
return;
}
}
});
client.on("messageReactionRemove", async (reaction, user) => {
if (reaction.message.partial) await reaction.message.fetch();
if (reaction.partial) await reaction.fetch();
if (user.bot) return;
if (!reaction.message.guild) return;
if (reaction.message.channel.id == channel) {
if (reaction.emoji.name === yellowTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(yellowTeamRole);
}
if (reaction.emoji.name === blueTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(blueTeamRole);
}
if (reaction.emoji.name === redTeamEmoji) {
await reaction.message.guild.members.cache.get(user.id).roles.remove(redTeamRole);
} else {
return;
}
}
});
},
};