rmarquet21
rmarquet21

Reputation: 144

My reaction on discord message return nothing

I try to make a bot that sends a message every morning at 9 o'clock with a possible reaction which for the moment writes me something in the console, the message on discord is sent well but the fact of clicking on l emoji does nothing, can you help me solve my problem? Here is the code:

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")
                }
            })
    });

Upvotes: 0

Views: 46

Answers (1)

Vincent Gonnet
Vincent Gonnet

Reputation: 148

Maybe you can try to use message.createReactionCollection() instead of message.awaitReactions().

Here is a code that works for me :

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

But be careful, as your message is sent automatically every day, don't check if the message author is the one who reacted : remove user.id === message.author.id

Upvotes: 1

Related Questions