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

657
Visualizações
Discord Bug Error Invalid Token in discord.js

So I want to create a bot discord for fun in JavaScript using discord.js.

I wrote this code:

const Discord = require("discord.js")
const client = new Discord.client()

client.once('ready',() => {
  console.log("Ready !");

});

client.login('token');

But when I'm trying to run it, I get this error:

/home/runner/MelodicPlainApplicationprogrammer/node_modules/discord.js/src/rest/RESTManager.js:32 const token = this.client.token ?? this.client.accessToken; ^ SyntaxError: Unexpected token '?'

This is on repl.it, and when I'm in VSCode, it works.

Why?

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

0

  1. You are using Discord.js v13 and Discord.js13 requires node.js v16 to work. Replit.com uses node.js v12 by default so you will need to set up node16 manually.

First, create a node.js repl enter image description here

Next, run npm install node@16 in shell enter image description here

After that you need to create a file called .replit

enter image description here

Inside the .replit file, add run = "npx node index.js". If your main file has a different name change index.js to your main file's name.

Now when you click run, replit uses node.js v16 instead of v12

  1. Now for the problems with your code:
const Discord = require("discord.js")
const client = new Discord.client()

client.once('ready',() => {
  console.log("Ready !");

});

client.login('token');

In the second line, const client = new Discord.client(), the c in Discord.client has to be capital, so write const client = new Discord.Client()

Now you need to add gateway intents so that your bot receives events. This is required in discord.js13 (Here's a list of gateway intents)

So change const client = new Discord.Client()

to const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] }) (You can add more intents if you want, these are just the basic ones)

You will also need to get your bot token and replace "token" in client.login('token'); with your bot token. Check this to see how to get your token.

Final code:

const Discord = require("discord.js")
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES"] })

client.once('ready',() => {
  console.log("Ready !");

});

client.login(enter your token here);
about 4 years ago · Juan Pablo Isaza Relatório

0

Most likely repl.it is running Node 12 or earlier. The error is saying that the operator ?? is a syntax error, meaning that it does not recognize the nullish coalescing operator. It is supported from Node 14.0.0 and later.

about 4 years ago · Juan Pablo Isaza Relatório

0

Try upgrading your node.js version (go to shell, next to console):

$ npm install node@16

Or you can downgrade your discord.js version to v12.5.3 in your json file, because v12 has way more tutorials than v13 at the moment.

The choice is upto you, you can upgrade your node.js version or downgrade your discord.js version

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