我刚刚开始尝试用discord.js设置discord机器人的javascript。我想将此机器人作为组织“文明6”小组的“简便”方法。因此,人们只需单击“ +”反应,即可将名称添加到列表中
const Discord = require('discord.js');
const client = new Discord.Client();
然后是前缀和令牌等...
client.on('message', message=>{
let args = message.content.slice(PREFIX.length).split(" ");
...用于检查命令的材料
然后是实际命令
switch(args[0]){
case 'civ':
const civ = new Discord.MessageEmbed()
.setTitle('Civ 6 Group')
.addField('Players Joined', message.author.username, true)
.setColor(0x00FFFF)
.setThumbnail(message.author.avatarURL)
.setFooter('Bot created by Plasy#0274')
message.channel.send(civ).then(sentEmbed => {
sentEmbed.react('718418753137803367');
sentEmbed.react('718421670276235344');
if (Discord.user.sentEmbed.react('718418753137803367'))then (message.channel.send('yes'))
})
break;
该如何做才能使其达到预期效果?我非常困惑,因此,我感谢您的帮助:)
答案 0 :(得分:0)
从这部分开始:
message.channel.send(civ).then(sentEmbed => {
sentEmbed.react('718418753137803367');
sentEmbed.react('718421670276235344');
您需要在消息上创建一个ReactionsCollector。
根据docs,您可以使用以下方法之一:
// Create a reaction collector
const filter = (reaction, user) => (reaction.emoji.id === '718418753137803367' || reaction.emoji.id === '718421670276235344') && user.id !== client.user.id;
const collector = message.createReactionCollector(filter, { time: 15000 });
collector.on('collect', (r, user) => {
console.log(`Collected ${r.emoji.name}`);
if (r.emoji.id === '718418753137803367') {
// Do something with reaction 1
}
else if (r.emoji.id === '718421670276235344') {
// Do something with reaction 2
}
});
// This is optional.
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
如果我很好地理解了您的问题,那么您可能还希望将新名称添加到嵌入中。假设您只有一个字段,则可以通过将代码放在“用...做某事”部分中来实现此目的:
sentEmbed.fields[0].value += `, ${user.username} *(Team 1 or 2)*`;
我希望这将使您走上正确的道路,如果还有其他疑问,请确保在下面发表评论