首页 > 解决方案 > 我怎样才能让我的机器人对反应做出反应?

问题描述

我目前正在尝试在我的机器人上创建一个带有反应的票务系统,它没有显示错误,但是当我做出反应时它不会给出“嗨”输出,我的代码如下:

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")
  })
  })
})

标签: javascriptdiscord.js

解决方案


bot 不响应的原因是它已经收集到了 bot 本身的消息中的✉️,因此它已经达到了它max的 1 反应。但它会检查这u.bot确实是true(在collect事件中),因此根本不会响应。

要解决此问题,您可以删除if(u.bot) return null;集合事件的内部,然后将其放入filter,如下所示:

const filter = (r, u) => r.emoji.name === "✉️" && !u.bot;

推荐阅读