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

417
Visualizações
Whenever I try to start my discord bot I get an error that says: ReferenceError: Discord is not defined

I'm working on this discord bot with a command handler, all the commands are in their own files which I import into the main file

This is my code:

const { Client, Intents } = require("discord.js");

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.commands = new Discord.Collection();
const fs = require('fs');
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for(const file of commandFiles){
    const command = require(`./commands/${file}`)
    client.commands.set(command.name, command) 
}

const { prefix, token } = require('./config.json')

client.once('ready', () => {
    console.log('BOT IS READY')
})

client.on('message', message => {
    if(!message.content.startsWith(prefix)||message.author.bot) return

    const args = message.content.slice(prefix.length).split(/ +/)
    const command = args.shift().toLowerCase()

    if(command === 'charlongolo'){
        client.commands.get('charlongolo').execute(message, args)
    } else if(command === 'timster'){
        client.commands.get('timster').execute(message, args)
    }
})

client.login(token);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The error is with how you import disord.js and then use it, so there is two ways you can go about this: You can either import the whole module, or import through object destructuring.

Whole Module

const Discord = require('discord.js');
...
const client = new Discord.Client({
    intents: [Discord .Intents.FLAGS.GUILDS, Discord .Intents.FLAGS.GUILD_MESSAGES]
})
client.commands = new Discord.Collection();

Object Destructuring

const { Client, Intents, Collection } = require("discord.js");
...
const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES]
});
client.commands = new Collection();
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