This repository has been archived by the owner on Jul 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
.array is not a function #8
Comments
i may fix the .array is not a function but the user that the bot pinged is now [object Map] |
ok finally fixed it const scheduler = require('node-schedule');
const GiveawayModel = require('../models/GiveawayModel');
function getWinner(users, max) {
if (users.length < 1) return false;
if (users.length <= max) return users;
const numbers = new Set();
const array = [];
let i = 0;
while(i < max) {
const random = Math.floor(Math.random() * users.length);
const selected = users[random];
if (!numbers.has(random)) {
array.push(selected);
i++
}
}
return array;
}
async function schedule(stuff, giveawayArray) {
for(let i = 0; i < giveawayArray.length; i++) {
let { messageId, channelId, endsOn, prize, winners } = giveawayArray[i];
scheduler.scheduleJob(`${messageId}`, endsOn, async () => {
const channel = stuff.client.channels.cache.get(channelId);
if (channel) {
const message = await channel.messages.fetch(messageId);
if (message) {
const { embeds, reactions } = message;
const reaction = reactions.cache.get('🎉');
const users = await reaction.users.fetch();
const entries = Array.from(users.filter((user) => !user.bot).keys());
if (embeds.length === 1) {
const embed = embeds[0];
const winner = getWinner(entries, winners);
let finalWinners;
if (!winner) {
finalWinners = 'Nobody Reacted';
}
else {
finalWinners = winner.map(user => user.toString()).join(', ');
}
embed.setDescription(`Winner(s): <@${finalWinners}>`);
embed.setFooter({ text: "Giveaway Ended" });
await message.edit({ embeds: [embed] });
if (!winner) {
message.channel.send(`Nobody reacted to the **${prize}** giveaway\n${message.url}`);
}
else {
message.channel.send(`Congratulations <@${finalWinners}>, you won the **${prize}**!\n${message.url}`);
}
const ended = await endGiveaway(messageId);
stuff.emit('giveawayEnd', ended);
}
}
}
});
}
}
async function endGiveaway(messageId) {
let data = await GiveawayModel.findOne({ messageId: messageId });
data.hasEnded = 'True';
await data.save();
return data;
}
module.exports = {
getWinner,
schedule,
endGiveaway
} |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
node_modules/discord-giveaway/src/functions.js:37
const entries = users.filter(user => !user.bot).array();
TypeError: users.filter(...).array is not a function
The text was updated successfully, but these errors were encountered: