Reputation: 429
I am trying to make a Discord.js giveaway command that send an embed, save it to the variable embedSent, collect the reactions after the TimeOut with the reactions.get() method, convert them to an array with array() then filter them with .filter(). The problem is at the Array() step where I keep getting the error TypeError: peopleReactedBot.array is not a function
.
Here is the part of my code :
embedSent.react("🎉");
setTimeout(function () {
try {
const peopleReactedBot = embedSent.reactions.cache.get("🎉").users.fetch();
const peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.author.id);
message.channel.send(peopleReacted)
} catch(e) {
return message.channel.send("An error has occured : `"+e+"`");
}
}, time);
I use Discord.js v12.
Upvotes: 1
Views: 1039
Reputation: 1464
user.fetch()
returns a Promise, so you might want to switch to an asynchronous function and await for the promise to complete, like so :
setTimeout(async () => {
try {
const peopleReactedBot = await embedSent.reactions.cache.get("🎉").users.fetch();
const peopleReacted = peopleReactedBot.array().filter(u => u.id !== client.author.id);
message.channel.send(peopleReacted)
} catch(e) {
return message.channel.send("An error has occurred : `"+e+"`");
}
}, time);
Upvotes: 1