Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am new to JavaScript so idk what to do now.

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading