javascript - 当发出命令的用户对以下选项之一做出反应时,如何让机器人编辑自己发送的消息?
问题描述
所以我正在开发一个创建频道的功能,将其放入一个类别,向该频道发送消息。所有这些目前都在工作,但是,我正在寻找一种方法让机器人通过使用 discordjs 的 awaitReactions 功能来听取对该消息的反应。
我目前在哪里:我已经对此事进行了一些研究,但我似乎无法弄清楚。我已经让机器人对自己的消息做出反应,但我希望它听取发出命令的用户是否对下面提供的反应之一做出反应。当发出命令的用户对消息做出反应时,我希望机器人发送的消息进行编辑并说其他内容。
let name = message.author.username;
let channel = message.guild.createChannel(name, {
type: "text",
permissionOverwrites: [{
id: message.author,
deny: ["MANAGE_MESSAGES"],
allow: ["SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: "466764415476432920",
deny: ["SEND_MESSAGES", "VIEW_CHANNEL"]
},
{
id: "642073025046642708",
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"]
},
{
id: "569736927427821569",
allow: ["VIEW_CHANNEL", "SEND_MESSAGES"]
}]
}).then(channel => {
let category = message.guild.channels.find(c => c.name == "Support Area" && c.type == "category");
if (!category) throw new Error("Category channel does not exist");
channel.setParent(category.id);
channel.send(`Life Can Be Ruff! - You’re not alone ${message.author} :heart:
Resources and coping skills while I connect you to a <@&569736927427821569>`).then(reactmessage => {
reactmessage.react(""),
reactmessage.react(""),
reactmessage.react("")
})
}).catch(console.error);
这就是我目前所在的位置。
解决方案
您可以等待来自特定用户的特定反应,如下所示:
const filter = (reaction, user) => {
return reaction.emoji.name === '' && user.id === message.author.id;
};
message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
.then(collected => console.log(collected.size))
.catch(collected => {
console.log(`Reacted! :D`);
});
这将等待一分钟!
推荐阅读
- ruby - 用于测试方法的 Rspec 匹配器在每个块内调用另一个方法
- html - 如何在所有页面上打印页脚而不与正文内容重叠?
- python - Discord.py 如何根据用户 ID 为特定用户设置命令
- angular - 角度库中的角度依赖注入问题
- reactjs - React/JSX 样式代码,标准源
- jmeter - 使用 JMeter 从文件夹中删除上传的文件
- java - 在Java中,“this”在继承该方法的子类上调用的超类方法中表示什么?
- pandas - 熊猫:按多列分组,找到最大值并将其他列保留在数据框中
- autodesk-forge - BIM 360 Revit 2021 DocumentOpened 事件错误
- ruby-on-rails - ActiveRecord 模型是否存在?运行缓慢 - 找到解决方案