我需要一个机器人来对发送命令的用户上方的消息做出反应。目前,该漫游器仅对发送该命令的用户做出反应。
client.on('message', (msg) => {
if (msg.content === 'Boo Hoo') {
const reactionEmoji = msg.guild.emojis.cache.find(
(emoji) => emoji.name === 'BooHoo'
);
msg.react(reactionEmoji);
}
});
我将如何修改/重写此代码,以使其对发送命令的用户上方的消息做出反应?我认为这可能与MessageManager有关,并且正在获取消息,但我不知道。
答案 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