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



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

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

这是一个以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 });
}
});

希望有人能帮帮我!

您需要添加反应侦听器 messageReaction在机器人加载 fetchMessage 或通过命令发送消息添加并获取消息(并将其保存到变量(

最新更新