I am fairly new to Discord.js and JavaScript, but decided to try my luck and start a little project to make a small Discord bot. It isn't supposed to be all fancy but I would like to get one specific function in it.
I would love to be able to make a text message in the Discord channel. Add three emojis as a reaction to that message. The goal is to give a user a specific role when he/she clicks a specific emoji.
It's a Pokemon Go themed bot. In the game there are three teams. I want to use the logo of those teams as emojis. So far so good. But when it comes to give users a role when they click a emoji? No clue? I did some research but I haven't found any extensive tutorials.
The code I have so far is listed beneath, if it is necessary. The !test command is the message I want to add the emojis to. The messsage itself works and looks like I want it to look.
const Discord = require("discord.js");
const { Client, RichEmbed } = require('discord.js');
const client = new Discord.Client();
client.on("ready", () => {
console.log("I am ready!");
});
client.on("message", (message) => {
if (message.content.startsWith("!ping")) {
message.channel.send("pong!");
}
});
client.on('message', message => {
if (message.content.startsWith("!test")) {
const embed = {
title: "Hello there!",
description: "Welcome to the world of Pokémon! My name is Oak! People call me the Pokémon Prof! This world is inhabited by creatures called Pokémon! For some people, Pokémon are pets. Other use them for fights. Myself… I study Pokémon as a profession.",
color: 5437293,
thumbnail: {
url: "https://cdn.bulbagarden.net/upload/8/84/Professor_Oak_XY.png"
},
fields: [
{
name: "But first, tell me a little about yourself.",
value: "Normally this is the part where I ask if you are a boy, or a girl and what your name is... But now I will just ask you what team you are in, so please let me know by clicking any of the three icons below! Your own very Pokémon legend is about to unfold! A world of dreams and adventures with Pokémon awaits!"
}
]
};
message.channel.send({ embed });
}
});
I hope someone can help me out!
You would need to add a reaction listener messageReactionAdd and fetch the message (and save it to a variable) on bot load fetchMessage or by sending it on a command