首页 > 解决方案 > Discord JS - 如何对同一个嵌入做出多次反应?

问题描述

我只得到了第一个“钱袋”表情符号来对频道中的最新消息做出反应,这是机器人发送的嵌入,但是,我希望机器人对“钱袋”和“钱袋”的新嵌入做出反应“票”表情符号,到目前为止,它会与“钱袋”表情符号做出反应,但是当它试图与“票”表情符号做出反应时会出错。如何让机器人对两个表情符号的新嵌入做出反应?


    if (message.content === '-new') {

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

        const embed = new Discord.RichEmbed()

        .setTitle('Ticket')

        .setColor('DC3BF5')

        .setDescription('Thank you for showing interest in purchasing a commission from the Quadra Build Team, or for lending us your time through Support. Make sure you have read our #terms-of-service channel before requesting a commission. We are glad to make your prolific ideas & requests come true!\n\n If you accidentally created a ticket by mistake, use (-del) to delete the ticket.\n\n React with :moneybag: to order a Commission.\n React with :tickets: to create a Support Ticket.\n -------------------------------------------------------------------------------------------------')

    message.channel.send(embed)
    .then(m => m.react(''))
    .then(m => m.react(''))
    .catch(m => {

        console.error('Emoji failed to react.');
    });
    message.awaitReactions(filter, { max: 1, time: 0, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '') {

            collected.on('collect', () => {

                m.clearReactions();

                var secondEmbed = new Discord.RichEmbed()

                .setTitle('Ticket')

                .setColor('DC3BF5')

                .setDescription('lol')
            });
        } else {

            collected.on('collect', () => {

                m.clearReactions();

                var secondEmbed = new Discord.RichEmbed()

                .setTitle('Ticket')

                .setColor('DC3BF5')

                .setDescription('lol 2')
            });
        }
    })
    .catch(collected => {
        message.channel.send('You didn\'t react with either of the specified emojis.');
    });
}

标签: javascriptbotsdiscorddiscord.js

解决方案


Message#react 在 Promise 中返回 MessageReaction,因此您需要执行以下操作:

message.channel.send(embed)
    .then(m => m.react(''))
    .then(m => m.message.react(''))

或者

message.channel.send(embed)
    .then(m => {
        m.react('')
        m.react('')
     });

或使用异步等待:

const m = await message.channel.send(embed);
await m.react('')
await m.react('')

推荐阅读