简体   繁体   中英

(discord.js) how to mention the user who react to the bot message?

How can I mention the user who reacted to my bot message?
I want to send message like, "@user reacted to my message,": here is my code:

msg.awaitReactions((reaction, user) => user.id == user.id && (reaction.emoji.name == '👍'), { max: 1, time: 30000 }).then(collected => {
    if (collected.first().emoji.name == '👍') {
        //here I want to send the message with the mention
    } else {
        //I added it for case that I going to use yes or no react question
    }
}).catch(() => {
    //maybe I will add here message that says the time passed.
});

After reading articles and troubleshooting I came up with the following solution:

    msg.awaitReactions((reaction, user) => user.id == user.id && (reaction.emoji.name == '👍'),
    { max: 1, time: 30000 }).then(collected => {
        const reaction = collected.first();
        if (collected.first().emoji.name == '👍') {
            const member = reaction.users.cache.find((user) => !user.bot);
            message.channel.send(`test is ${member}`)
        } else {
            //I added it for case that I gonna use yes or no react question
}
    }).catch(() => {
        //maybe I will add here message that says the time passed.
    });

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