我对 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 });
}
});
我希望有人可以帮助我!