Discord.js message after receiving emoji reaction

瘦欲@ 提交于 2019-12-21 05:42:08

问题


It it possible to make a Discord bot send a message once a previous message has received a reaction? I was thinking about something like:

if(cmd === `${prefix}list`) {
    var i = 0;

    let embed = new Discord.RichEmbed()
      .addField("List", "Content");

    let anotherembed = new Discord.RichEmbed()
      .addField("Message", "List has been completed!");

    return message.channel.send(embed);

    do {
      message.channel.send(anotherembed + 1);
    }
    while (i !== 0) && (reaction.emoji.name === "✅");

}

回答1:


That's not something you should do.
What you want is message.awaitReactions.
There is a great guide by the DiscordJS team and community that has a great example for awaitReactions.
Here is the link and an example they used:

message.react('👍').then(() => message.react('👎'));

const filter = (reaction, user) => {
    return ['👍', '👎'].includes(reaction.emoji.name) && user.id === message.author.id;
};

message.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '👍') {
            message.reply('you reacted with a thumbs up.');
        }
        else {
            message.reply('you reacted with a thumbs down.');
        }
    })
    .catch(collected => {
        console.log(`After a minute, only ${collected.size} out of 4 reacted.`);
        message.reply('you didn\'t react with neither a thumbs up, nor a thumbs down.');
    });

You basically need a filter, that only allows for a range of emojis, and a user to "use" them.

And also somewhere on your code you have:

return message.channel.send(embed);

You should remove the return part, or else it will just return and don't do the rest of the code.



来源:https://stackoverflow.com/questions/49842712/discord-js-message-after-receiving-emoji-reaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!