Hello. I was trying to create an global message reaction collector in my discord bot, but it returns undefined.
Here’s the code of the function:
client.awaitReact = async (msg, question, emojis) => {
const filter = (reaction, user) => {return emojis.includes(reaction.emoji.name) && user.id === msg.author.id;};
try {
await msg.channel.send(question).then(async sentEmbed => {
for (var emoji in emojis) {
sentEmbed.react(emojis[emoji])
}
const collected = await sentEmbed.awaitReactions(filter, { max: 1, time: 60000, errors: ['time'] })
console.log(collected.first().emoji.name)
return collected.first().emoji.name
})
} catch (e) {return false}
}
I call it like this:
let reaction = await client.awaitReact(message, embed, ['📗', '📕', '❌'])
The console.log in the function prints the emoji, but when I use the console.log after calling the function, it returns undefined.
Why is this happening?