Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
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.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!