【问题标题】:Discord JS - How to react multiple times to the same embed?Discord JS - 如何对同一个嵌入做出多次反应?
【发布时间】:2020-01-21 17:08:36
【问题描述】:

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


    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.');
    });
}

【问题讨论】:

  • 错误是什么
  • 运行控制台报错"Emoji faile to react."
  • 您能否尝试摆脱.catch(m => { console.error('Emoji failed to react.'); }); 并告诉我们实际的错误是什么?
  • 去掉了.catch语句,现在的错误是“m.react is not a statement.”。我相信 M 应该是 Javascript 的标识符,但它在此代码中的目的是确保机器人对其发送的嵌入做出反应,而不是用户的消息。

标签: javascript bots discord discord.js


【解决方案1】:

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('?')

【讨论】:

  • 该死,你打败了我 :)
  • 谢谢 Plasma! :D
【解决方案2】:

第一个 .then() 实际上返回一个 MessageReaction 对象,这就是您收到此错误的原因(无法在 MessageReaction 上调用 .react())。

你可以1。使用异步/等待

async function() {
const embed = await message.channel.send('test')
await embed.react('?')
await embed.react('?')
}

2。使用MessageReactionmessage属性

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

【讨论】:

  • 谢谢弗朗索瓦!
猜你喜欢
  • 2022-01-08
  • 2021-05-12
  • 2021-11-17
  • 2020-11-28
  • 1970-01-01
  • 2020-12-13
  • 2021-03-11
  • 2017-10-25
  • 2020-06-13
相关资源
最近更新 更多