javascript - 反应后 Discord.js 编辑消息
问题描述
我刚刚开始使用 javascript 尝试使用 discord.js 设置一个不和谐机器人。我想用这个机器人作为组织突袭的“简单”方式。因此,人们只需点击图标即可登录突袭。
const Discord = require('discord.js');
const bot = new Discord.Client();
...令牌,前缀等
bot.on('message', message => {
if (message.content.startsWith(PREFIX)) {
let args = message.content.substring(PREFIX.length).split(" ");
...一些检查命令的东西
message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
messageReaction.react('✅');
});
到目前为止,代码工作正常。它检查日期和时间就好了。现在我想检测是否有人对消息做出反应,并通过编辑在消息中提及他。而且我只是不知道如何使用awaitReactions
. 或者,如果它甚至可以与awaitReactions
.
解决方案
您可以替换您当前的消息功能
message.channel.send('RaidID: ' + RaidID + '\nRaid: GOS \nRaid Leader: <@' + message.author.id + '> \nDate: ' + args[2] + '\nTime: ' + args[3]).then(messageReaction => {
messageReaction.react('✅');
});
使用此功能:
message.channel
.send(
"RaidID: " +
RaidID +
"\nRaid: GOS \nRaid Leader: <@" +
message.author.id +
"> \nDate: " +
args[2] +
"\nTime: " +
args[3]
)
.then((messageReaction) => {
messageReaction.react("✅");
messageReaction.awaitReactions((args, user) => {
return !user.bot && args._emoji.name === "✅";
}, { max: 1 }).then(reaction => {
// SOMEONE REACTED
console.log('REACTION');
});
});
它在 promise中添加了.awaitReactions
函数。.then
它检查用户和表情符号✅是否做出反应。如果反应正确,// SOMEONE REACTED
则调用 at 部分。
推荐阅读
- c# - HttpClient导致验证码,而浏览器中的同一页面没有
- python - 如何将数据框列转换为 UTC 日期时间格式?
- sql - 在表第 2 部分中搜索相反的值
- cryptography - 如何将导出的 Cosmos SDK 私钥转换为 Keplr 或 Metamask 可以导入的格式?
- c++ - 将类对象转换为结构对象 C/C++
- docker - Neo4J Docker-compose 在启动时加载 CSV 数据
- android - 使用底部导航内的回收站视图显示数据
- prolog - 如何通过其他关系延长理解连接
- lance - 球员位置弯曲与墙壁碰撞
- php - Woocommerce - 从单个产品、结帐、电子邮件发票和感谢屏幕中的产品价格中减去自定义字段金额