Reputation: 147
I need a bot to react to a message above the user who sent the command. Right now the bot only reacts to the user who sent the command.
client.on('message', (msg) => {
if (msg.content === 'Boo Hoo') {
const reactionEmoji = msg.guild.emojis.cache.find(
(emoji) => emoji.name === 'BooHoo'
);
msg.react(reactionEmoji);
}
});
how would I modify/rewrite this code to make it react to a message above the user who sent the command? I'm thinking it might have something to do with MessageManager, and fetching messages but I don't know.
Upvotes: 2
Views: 606
Reputation: 8402
Here, use the .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
Upvotes: 1