I am trying to code a role reaction for my discord bot. Currently, right now I am stuck on how to make it so multiple people can react to the message to receive a role(s) or remove role(s). I would also like the embed message to be a constant message.
Any guidance would be helpful as I have been trying to code this for several days and I just cant get it.
This is my current code:
const Discord = require("discord.js");
const colors = require("../colors");
const botconfig = require("../botconfig")
module.exports.run = async (bot, message, args) => {
const eRole = message.guild.roles.get('688477690344374283'); // Events
const uRole = message.guild.roles.get('688477558982836344'); // Updates
const pRole = message.guild.roles.get('688477868078137369'); // Polls
const smRole = message.guild.roles.get('687498488295981069'); // Social Media
const qRole = message.guild.roles.get('688477467840872452'); // QOTD
const filter = (reaction, user) => ['❤️', '????', '????', '????','????'].includes(reaction.emoji.name) && user.id === message.author.id;
let embed = new Discord.RichEmbed()
.setTitle('Pinged Roles')
.setDescription(`
❤️ ${eRole.toString()}
???? ${uRole.toString()}
???? ${pRole.toString()}
???? ${smRole.toString()}
???? ${qRole.toString()}
`)
.addField("**TIP:**", "Double react to remove a role")
.setColor(colors.aqua)
.setTimestamp()
.setFooter(`mc.advancius.net`,bot.user.displayAvatarURL)
message.channel.send(embed).then(async msg => {
await msg.react('❤️');
await msg.react('????');
await msg.react('????');
await msg.react('????');
await msg.react('????');
msg.awaitReactions(filter, {
max:1,
}).then(collected => {
const reaction = collected.first();
switch (reaction.emoji.name) {
case '❤️':
if (message.member.roles.has(eRole.id)) {
return message.channel.send('You are already in this role!').then(m => m.delete(3000));
}
message.member.addRole(eRole).catch(err => {
console.log(err);
return message.channel.send(`Error adding you to this role: **${err.message}**.`);
});
message.channel.send(`You have been added to the **${eRole.name}** role!`).then(m => m.delete(3000));
break;
case '????':
if (message.member.roles.has(uRole.id)) {
return message.channel.send('You are already in this role!').then(m => m.delete(3000));
}
message.member.addRole(uRole).catch(err => {
console.log(err);
return message.channel.send(`Error adding you to this role: **${err.message}**.`);
});
message.channel.send(`You have been added to the **${uRole.name}** role!`).then(m => m.delete(3000));
break;
case '????':
if (message.member.roles.has(pRole.id)) {
return message.channel.send('You are already in this role!').then(m => m.delete(3000));
}
message.member.addRole(pRole).catch(err => {
console.log(err);
return message.channel.send(`Error adding you to this role: **${err.message}**.`);
});
message.channel.send(`You have been added to the **${pRole.name}** role!`).then(m => m.delete(3000));
break;
case '????':
if (message.member.roles.has(smRole.id)) {
return message.channel.send('You are already in this role!').then(m => m.delete(3000));
}
message.member.addRole(smRole).catch(err => {
console.log(err);
return message.channel.send(`Error adding you to this role: **${err.message}**.`);
});
message.channel.send(`You have been added to the **${smRole.name}** role!`).then(m => m.delete(3000));
break;
case '????':
if (message.member.roles.has(qRole.id)) {
return message.channel.send('You are already in this role!').then(m => m.delete(3000));
}
message.member.addRole(qRole).catch(err => {
console.log(err);
return message.channel.send(`Error adding you to this role: **${err.message}**.`);
});
message.channel.send(`You have been added to the **${qRole.name}** role!`).then(m => m.delete(3000));
break;
};
});
})
};
exports.help = {
name: 'roles2'
};