让机器人对上面的消息做出反应

时间:2020-08-26 02:53:12

标签: javascript node.js discord discord.js

我需要一个机器人来对发送命令的用户上方的消息做出反应。目前,该漫游器仅对发送该命令的用户做出反应。

client.on('message', (msg) => {
 if (msg.content === 'Boo Hoo') {
  const reactionEmoji = msg.guild.emojis.cache.find(
   (emoji) => emoji.name === 'BooHoo'
  );
  msg.react(reactionEmoji);
 }
});

我将如何修改/重写此代码,以使其对发送命令的用户上方的消息做出反应?我认为这可能与MessageManager有关,并且正在获取消息,但我不知道。

1 个答案:

答案 0 :(得分:1)

在这里,使用.fetch() method

message.channel.messages
 .fetch({ limit: 2 }) // get the two latest messages in that channel (cmd and the one aaobve it)
 .then((messages) => messages.last().react(reactEmoji)); // get last (second) entry and react to it