node.js - 最大反应 Discord.js 的问题
问题描述
我的目标是使用一个添加反应的命令,您可以对更改文本做出反应,所以当我单击并将原始文本编辑为的反应 1 为 : 1 和其他相同...这非常有效,但是当我正在尝试删除并重新添加反应,这不起作用我认为这是因为:{ max: 1 }
这是我的代码:
bot.on('message', msg => {
if(msg.content === PREFIX + "test") {
msg.channel.send(`${msg.author.username}, exemple`).then((sentMessage) => {
setTimeout(function() {
sentMessage.react("⏪");
}, 500);
setTimeout(function() {
sentMessage.react("⬅️");
}, 1000);
setTimeout(function() {
sentMessage.react("➡️");
}, 1500);
setTimeout(function() {
sentMessage.react("⏩");
}, 2000);
let reactionFilter = (reaction, user) => {
reaction.emoji.name === '⏪' && user.id !== "bot id" && user.id == msg.author.id
}
sentMessage.awaitReactions(reactionFilter, { max: 1 }).then(() => {
sentMessage.edit(`1`)
}
)
let reactionFilter2 = (reaction, user) => {
reaction.emoji.name === '⬅️' && user.id !== "bot id" && user.id === msg.author.id
}
sentMessage.awaitReactions(reactionFilter2, { max: 1 }).then(() => {
sentMessage.edit(`2`)
}
)
let reactionFilter3 = (reaction, user) => {
reaction.emoji.name === '➡️' && user.id !== "bot id" && user.id === msg.author.id
}
sentMessage.awaitReactions(reactionFilter3, { max: 1 }).then(() => {
sentMessage.edit(`3`)
}
)
let reactionFilter4 = (reaction, user) => {
reaction.emoji.name === '⏩' && user.id !== "bot id" && user.id === msg.author.id
}
sentMessage.awaitReactions(reactionFilter4, { max: 1 }).then(() => {
sentMessage.edit(`4`)
}
)
})
}
})
谢谢 !
解决方案
是的,这是因为最大限制,您应该改为使用一个反应收集器:
const emojis = ["⏪", "⬅️", "➡️", "⏩"];
//no need to check if the user id isnt the bot
const filter = (reaction, user) => emojis.includes(reaction.emoji.name) && user.id === msg.author.id;
// adding a time is probably a better option
const collector = sentMessage.createReactionCollector(filter, { time: 5000 });
collector.on("collect", reaction => {
// array is 0 indexed so just add 1 to the index and you get the number you wanted
// might need to convert the number into a string aswell
sentMessage.edit("" + (emojis.indexOf(reaction.emoji.name) + 1));
});
应该注意,如果删除了反应,这不会做任何事情,我认为这是最好的,因为在删除后很难确定文本应该是什么
推荐阅读
- c# - ASP.NET MVC:当我按下编辑时,我的日历没有采用模型日期值
- typescript - 如何在 nuxt store 的 action 中接近 axios
- esp8266 - i2cdetect 没有显示任何地址
- flutter - 从 GetView 或 GetResponsiveView 导航后每次调用的构建方法
- html - 如何在打印布局和嵌入 html 文档时强制 MS Word 具有相同的布局?
- html - 结构化数据不适用于 CSS 选择器(在链接中添加斜杠和其他问题)。我该如何解决?
- pandas - 将股票图表的趋势线向右延伸
- backup - 如果没有备份,是否可以在远程 Mac 上从 Big Sur 降级到 Catalina?
- c# - C#模拟telerik ui类
- curl - 无法向 Plaid 发出 API 请求