javascript - 我怎样才能让我的机器人对反应做出反应?
问题描述
我目前正在尝试在我的机器人上创建一个带有反应的票务系统,它没有显示错误,但是当我做出反应时它不会给出“嗨”输出,我的代码如下:
client.on("ready", async () => {
const guild = client.guilds.cache.get("my server ID")
const channel = guild.channels.cache.get("the channel ID")
const message = guild.channels.cache.get("the same channel ID").send(new Discord.MessageEmbed()
.setAuthor("Tickets", guild.iconURL({ dynamic: true })).setDescription("React to the emoji below to start a ticket")).then(sent => {
sent.react("✉️")
const filter = (r, u) => r.emoji.name === "✉️";
const collector = sent.createReactionCollector(filter, { max: 1 });
collector.on("collect", (r, u) => {
if(u.bot) return null;
else channel.send("Hi")
})
})
})
解决方案
bot 不响应的原因是它已经收集到了 bot 本身的消息中的✉️,因此它已经达到了它max
的 1 反应。但它会检查这u.bot
确实是true
(在collect
事件中),因此根本不会响应。
要解决此问题,您可以删除if(u.bot) return null;
集合事件的内部,然后将其放入filter
,如下所示:
const filter = (r, u) => r.emoji.name === "✉️" && !u.bot;
推荐阅读
- python - Python中的网络爬虫
- jenkins - 在后期检查每个阶段的结果 - Jenkins Pipeline
- php - xss_clean 删除 tinymce 的格式
- php - 如何检查 shell 命令是否从 PHP 运行
- powerbi - PowerBI - DateAdd 最大值
- sql - 使用 CSV 列和来自其他列的电子邮件的 SQL 查询
- paypal - 如何重定向到 PayPal-Sandbox 上其他版本的结帐页面
- python - Sphinx - 如何更改函数参数的格式样式
- rust - 您如何将参数用于在错误处理代码中出错的函数?
- linux - 如何通过 ssh 连接覆盖本地 bash 脚本变量?