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

173
Visualizações
Discord Bot initialization Failure

I have a problem in creating the main file for my discord bot. currently, i encountered a problem in trying to get my bot to work but sadly, this error message has been outputted from the console.

PS C:\Users\Kelvin Wang\Documents\Projects\DiscordBot> node index.js
node:internal/modules/cjs/loader:1170
    throw err;
     ^

SyntaxError: C:\Users\Kelvin Wang\Documents\Projects\DiscordBot\config.json: Unexpected end of JSON input

    at parse (<anonymous>)
    at Object.Module._extensions..json (node:internal/modules/cjs/loader:1167:22)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\Kelvin Wang\Documents\Projects\DiscordBot\index.js:4:19)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)

My code in index.js is this:

//initial discord initialization of client and library
// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');
const dotenv = require('dotenv');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ferraribot is online!');
});

// Login to Discord with your client's token
client.login(token);

While my config.json looks like this:

{
"token": "token"
}

Any help would be much appreciated! This is my first time using stack overflow so I'm sorry for any wrong formatting that I've done. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Your code looks just fine.

The error said, your code has some problems reading the JSON config. (is it in the same directory?)

  • First try your code using your token in the index.js. client.login(*****) // just don't upload e.g. github ;)
  • Second, I believe better practice using .env for sensitive information. https://www.npmjs.com/package/dotenv
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