javascript - 根据反应编辑机器人的消息
问题描述
我刚刚开始使用 javascript 尝试使用 discord.js 设置一个不和谐机器人。我想使用这个机器人作为组织“文明 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;
我能做些什么来使这项工作如我所愿?我非常卡住,所以我很感激任何帮助:)
解决方案
从这部分开始:
message.channel.send(civ).then(sentEmbed => {
sentEmbed.react('718418753137803367');
sentEmbed.react('718421670276235344');
您需要在消息上创建一个反应收集器。
根据文档,您可以这样制作:
// 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`));
如果我很好地理解了您的问题,那么您可能还想将新名称添加到您的嵌入中。假设您只有一个字段,您可以通过将此代码放在“do something with...”部分中来实现这一点:
sentEmbed.fields[0].value += `, ${user.username} *(Team 1 or 2)*`;
我希望这会让您走上正确的道路,如果您有任何其他问题,请务必在下面发表评论
推荐阅读
- python - Python from django.contrib.auth.views import logout ImportError: cannot import name 'logout'
- sed - 使用 sed 删除所有块中的特定行值
- javascript - Angular不显示html页面
- javascript - 在javascript中实现幂函数
- c++ - 将派生对象传递给构造函数时出现错误 C2664
- ruby-on-rails - 所有公寓子域中的 Rails 请求
- swift - 将 dosumentSnapshot 分配给自定义对象?
- python - python中的分布图
- python - 在 Unix 系统上使用 Python Ctypes 函数调用分段错误
- javascript - 如何添加 ScrollMagic 做出反应?