Discord.js/JavaScript:如何让用户选择角色?

Discord.js/JavaScript: How can I let a user choose a role?

我是 Discord.js 和 JavaScript 的新手,但我决定试试运气,开始一个小项目来制作一个小型 Discord 机器人。它不应该很花哨,但我想在其中获得一个特定的功能。

我希望能够在 Discord 频道中发送短信。添加三个表情符号作为对该消息的反应。目标是在 he/she 单击特定表情符号时为用户赋予特定角色。

这是一款以 Pokemon Go 为主题的机器人。比赛中共有三支球队。我想将这些团队的徽标用作表情符号。到目前为止,一切都很好。但是当涉及到在用户单击表情符号时赋予用户角色时?没有线索?我做了一些研究,但没有找到任何广泛的教程。

如果需要的话,我目前的代码列在下面。 !test 命令是我要添加表情符号的消息。消息本身有效,看起来就像我想要的那样。

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 });
  }
});

希望有人能帮帮我!

您需要添加反应侦听器messageReactionAdd and fetch the message (and save it to a variable) on bot load fetchMessage或通过命令发送它