'JavaScript Discord Bot Level System through Discord-XP
When I do command !leaderboard I'll get an error. I have this code for the leaderboard.js file:
const Levels = require('discord-xp');
module.exports = {
name: 'leaderboard',
description: 'Leaderboard Command :)',
async execute(message, args, client){
const rawLeaderboard = await Levels.fetchLeaderboard(message.guild.id, 5); // We grab top 10 users with most xp in the current server.
if (rawLeaderboard.length < 1) return reply("Nikdo není v žebříčku.");
const leaderboard = await Levels.computeLeaderboard(client, rawLeaderboard); // We process the leaderboard.
const lb = leaderboard.map(e => `${e.position}. ${e.username}#${e.discriminator}\nLevel: ${e.level}\nXP: ${e.xp.toLocaleString()}`); // We map the outputs.
message.channel.send(`**Leaderboard**:\n\n${lb.join("\n\n")}`);
}
}
This is the error I get:
C:\Users\xb06\Desktop\Sanoy\node_modules\discord-xp\index.js:262
if (!client) throw new TypeError("A client was not provided.");
^
TypeError: A client was not provided.
at Function.computeLeaderboard (C:\Users\xb06\Desktop\Sanoy\node_modules\discord-xp\index.js:262:24)
at Object.execute (C:\Users\xb06\Desktop\Sanoy\commands\leaderboard.js:10:42)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
I've tried everything I could, searched on web, and so long, but I can'ť resolve the error.
I am new to JavaScript so idk what to do now.
Solution 1:[1]
I checked the source code of that discord-xp library, and it seems that your client is a falsy value (most likely undefined). Make sure your function is being executed properly
command.execute(message, args, client)
With all 3 of those arguments, in that order
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | MrMythical |
