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

549
Views
Discord Bot ReferenceError: Client is not defined

I keep getting this error;

 ReferenceError: client is not defined
    at Object.<anonymous> (C:\Users\aggie\Downloads\Bot\bot.js:3:1)
←[90m    at Module._compile (internal/modules/cjs/loader.js:1085:14)←[39m
←[90m    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)←[39m
←[90m    at Module.load (internal/modules/cjs/loader.js:950:32)←[39m
←[90m    at Function.Module._load (internal/modules/cjs/loader.js:790:12)←[39m
←[90m    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:76:12)←[39m
←[90m    at internal/main/run_main_module.js:17:47←[39m

My bot.js code is

let ratelimits = [];

client.on("message", (msg) => {
    // APPLYING RATELIMITS
    const appliedRatelimit = ratelimits.find(
        (value) => 
            value.user === msg.author.id && value.channel === msg.channel.id
    );
    if (appliedRatelimit) {
        // Can they post the message?
        const canPostMessage =
            msg.createdAt.getTime() - appliedRatelimit.ratelimit >=
            appliedRatelimit.lastMessage;

        // They can
        if (canPostMessage)
            return (ratelimits[
                ratelimits.indexOf(appliedRatelimit)
            ].lastMessage = msg.createdAt.getTime());

        // They can't
        msg.delete({ reason: "Enforcing ratelimit." });
    }

    // SET RATELIMIT
    if (msg.content === "!ratelimit") {
        // Checking it's you
        if (msg.author.id !== "705923685877415979") return msg.reply("ok.");

        // You can change these values in function of the received message
        const targetedUserId = "529395455109627925";
        const targetedChannelId = msg.channel.id;
        const msRateLimit = 25000; // 25 seconds

        // Delete existant ratelimit if any for this user on this channel
        ratelimits = ratelimits.filter(
            (value) =>
                !(
                    value.user === targetedUserId &&
                    value.channel === targetedChannelId
                )
        );

        // Add ratelimit
        ratelimits.push({
            user: targetedUserId,
            channel: targetedChannelId,
            ratelimit: msRateLimit,
            lastMessage: 0,
        });
    }

    // CLEAR RATELIMITS
    if (msg.content === "!clearRatelimits") {
        // Checking it's you
        if (msg.author.id !== "your id") return msg.reply("You can't do that.");
        // Clearing all ratelimits
        ratelimits = [];
    }
});

I wanted to put slow mode on certain users because they keep spamming the chat, what am I doing wrong? Sorry if I missed something obvious it's my first time making a bot. I copied it from a post on here because I'm still a beginner in javascript.

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

0

At the top of your code, add

const Discord = require('discord.js')
const client = new Discord.Client()

If you run into any other problems, check the discord.js guide

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!