【问题标题】:My reaction on discord message return nothing我对不和谐消息的反应什么也没返回
【发布时间】:2021-11-06 02:51:30
【问题描述】:

我尝试制作一个机器人,它每天早上 9 点发送一条消息,可能的反应是暂时在控制台中给我写一些东西,discord 上的消息发送得很好,但是点击 l 表情符号的事实什么都不做,你能帮我解决我的问题吗?代码如下:

var rule = new schedule.RecurrenceRule();
    rule.hour = 9;
    rule.minute = 0;
    rule.tz = 'Europe/Paris';
    schedule.scheduleJob(rule, async function() {
        var question = await getQuestion();
        message = await client.channels.cache.get(process.env.CHANNEL_ID).send(`**hello @everyone The wake up question.** \n${question}`)
        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 === '????') {
                    console.log("message")
                }
            })
    });

【问题讨论】:

  • 确保您拥有GUILD_MESSAGE_REACTIONS

标签: javascript node.js discord discord.js


【解决方案1】:

也许你可以尝试使用 message.createReactionCollection() 而不是 message.awaitReactions()。

这是一个适合我的代码:

msg.react('❌');

const filter1 = (reaction, user) => reaction.emoji.name === '❌' && user.id === message.author.id;

const collector1 = msg.createReactionCollector(filter1, {time: 60000});
  collector1.on('collect', () => {
  msg.delete();
})

//This is a code that works for me, but in your code you don't want to filter reactions with user.id === message.author.id, as the one who will react isn't the one who sent the message

但请注意,由于您的消息每天都会自动发送,因此请不要检查消息作者是否是做出反应的人:删除user.id === message.author.id

【讨论】:

    猜你喜欢
    • 2022-01-09
    • 2021-06-25
    • 2021-05-08
    • 2023-03-30
    • 2020-11-20
    • 2021-11-03
    • 2021-08-08
    • 2020-12-06
    • 1970-01-01
    相关资源
    最近更新 更多