-
-
Save JakyeRU/fde26f3d89d7382b2f8bf659cecb30a4 to your computer and use it in GitHub Desktop.
/* | |
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 | |
} | |
}) | |
}); |
I get this error when running the code
(node:168076) UnhandledPromiseRejectionWarning: ReferenceError: discord is not defined
I get this error when running the code
(node:168076) UnhandledPromiseRejectionWarning: ReferenceError: discord is not defined
As the error suggests, discord
is not defined within your code. You can fix that by defining it.
const discord = require("discord.js");
How do I get others to also assign a role, and not just me :(
what do i need to type for this code to work
Thanks a lot bro It works fine!
Might want to capitalize discord in const Embed = new discord.MessageEmbed()
it didn't work without it for me.
Might want to capitalize discord in
const Embed = new discord.MessageEmbed()
it didn't work without it for me.
It depends on how you required discord.js in your file.
Might want to capitalize discord in
const Embed = new discord.MessageEmbed()
it didn't work without it for me.It depends on how you required discord.js in your file.
You're right my bad. Nice command though anyways.
Might want to capitalize discord in
const Embed = new discord.MessageEmbed()
it didn't work without it for me.It depends on how you required discord.js in your file.
You're right my bad. Nice command though anyways.
No worries! Thanks for the support.
Hi!
When I do the command that I have defined (to send the embed etc), the embed work fine, and when I click on the reaction, nothing... My role is set with the good ID and the variable ${Role.name} work too in the embed but I didn't get the role, no error message :/
Hi!
When I do the command that I have defined (to send the embed etc), the embed work fine, and when I click on the reaction, nothing... My role is set with the good ID and the variable ${Role.name} work too in the embed but I didn't get the role, no error message :/
Hello.
Please open a an issue here with the full code.
Hey, I was wondering what the max uses are for it. I know it says 1 but will it also work if you set it to (idunno sth like) 5?
Hi!
When I do the command that I have defined (to send the embed etc), the embed work fine, and when I click on the reaction, nothing... My role is set with the good ID and the variable ${Role.name} work too in the embed but I didn't get the role, no error message :/Hello.
Please open a an issue here with the full code.
I'm very sorry I just have made a mistake by editing the emoji (I forgot to edit the emoji in the "case" part), I don't have problems anymore, sorry for the disturb ^^
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 ? ^^'
How do i even set this up