diff --git a/src/commands/top.ts b/src/commands/top.ts index f9c9ed6..c9e1245 100644 --- a/src/commands/top.ts +++ b/src/commands/top.ts @@ -14,7 +14,7 @@ export async function execute(interaction) { userScore .find({}) .sort({ score: -1 }) // Sort by descending order - .exec((err, obj) => { + .exec(async (err, obj) => { if (err) { log({ logger: 'top', content: `Getting top players failed: ${err}`, level: 'error' }); console.log(err); @@ -42,11 +42,10 @@ export async function execute(interaction) { embeds.push(leaderboardEmbed); let sMessageContent = ''; - const members = interaction.guild.members.cache; + const members = await interaction.guild.members.fetch(); - const serverLeaderBoardArray = obj.filter(o => members.some(m => m.user.id === o.authorID)); - console.log(serverLeaderBoardArray[0]); - if (serverLeaderBoardArray.length < 10) { + const serverLeaderBoardArray = await obj.filter(o => members.some(m => m.user.id === o.authorID)); + if (serverLeaderBoardArray.length > 10) { for (let i = 0; i < 10; i++) { sMessageContent += `${i + 1}: <@${serverLeaderBoardArray[i].authorID}>: ${serverLeaderBoardArray[i].score}\n`; } diff --git a/src/index.ts b/src/index.ts index 0f17f45..575fa2c 100755 --- a/src/index.ts +++ b/src/index.ts @@ -6,7 +6,7 @@ import { token } from './helpers/env'; import log from './helpers/log'; const client = new Client({ - intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS], + intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS, Intents.FLAGS.GUILD_MEMBERS, Intents.FLAGS.DIRECT_MESSAGES, Intents.FLAGS.DIRECT_MESSAGE_REACTIONS], }); client['commands'] = new Collection();