Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

552
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda