Last active
September 24, 2022 14:59
-
-
Save JakyeRU/fde26f3d89d7382b2f8bf659cecb30a4 to your computer and use it in GitHub Desktop.
Discord.js V12 - ReactionRole | Add a role using reactions.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
NOTE: This gist is no longer supported and won't get updated. | |
Please refer to https://github.com/JakyeRU/discord.js-examples for the latest version. | |
If you have any issues/suggestions you can open an issue/pull request there. | |
*/ | |
client.on("message", async message => { | |
// Checking if the message author is a bot. | |
if (message.author.bot) return false; | |
// Getting the role by ID. | |
const Role1 = message.guild.roles.cache.get("RoleID"); | |
// Creating a filter. | |
const Filter = (reaction, user) => user.id == message.author.id; | |
// Creating the embed message. | |
const Embed = new discord.MessageEmbed() | |
.setDescription(`Choose a role: ${Role1.name}`) | |
// Awaiting for the embed message to be sent. | |
const reactionMessage = await message.channel.send(Embed); | |
// Reacting to the embed message. | |
await reactionMessage.react("😎"); | |
// Awaiting a reaction to the embed message. Time is measured in ms. (30000 ms - 30 seconds) | |
reactionMessage.awaitReactions(Filter, {max: 1, time: 30000, errors: ["time"]}).then(collected => { | |
// Getting the first reaction in the collection. | |
const reaction = collected.first(); | |
// Creating a switch statement for reaction.emoji.name. | |
switch (reaction.emoji.name) { | |
case "😎": | |
// Checking if the member already has the role. | |
if (message.member.roles.cache.has(Role1.id)) {return message.channel.send("You already have the role.")}; | |
// Adding the role. | |
message.member.roles.add(Role1).then(message.channel.send("Role added!")); | |
// Breaking the switch statement to make sure no other cases are executed. | |
break | |
} | |
}) | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heyy
all this is nice, thanks soo much !
but i don't understand how to send the embed in my discord server, can someone help me please ? ^^'