简体   繁体   中英

Is there a way to React to a Certain Message in discord.js Using Message IDs?

I'm aware of message.react(); , but I can't seem to find anything that specifically reacts to a message using message IDs. My code now reads as

    if(message.content.startsWith('$react')) {
        let splicedMessage = message.content.slice(7);
        let messageParts = splicedMessage.split(' ');
        let pendingMessage = messageParts[0];
        let pendingReaction = messageParts[1];
    }

eg "$react (messageID) (reaction)". Is there any way that I can react to messageID ( pendingMessage in the code) with the specified reaction?

First, you need to fetch the message , and then react to it. I'm assuming that the message is in the channel that you're invoking the command in:

message.channel.fetchMessage(pendingMessage)
    .then(msg => msg.react(pendingReaction));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM