discord.js: A valid token is being considered invalid

Please describe the problem you are having in as much detail as possible: I can’t login to the client and the ready event is never fired. Here’s the error I’m getting

(node:689) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at Client.login (/home/runner/<project>/node_modules/discord.js/src/client/Client.js:206:52)
    at Object.<anonymous> (/home/runner/<project>/index.js:2222:20)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:689) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:689) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Include a reproducible code sample here, if possible:

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

client.on('ready', () =>{
console.log('It works!') // Never fires :/
})

client.login('<token>') // yes, I have double checked many times that it is correct

Further details:

  • discord.js version: 12.5.1
  • Node.js version: Latest stable
  • Operating system: Repl.it
  • Priority this issue should have – please be realistic and elaborate if possible: Not sure, but it happens at random
  • This happens randomly, and only for one instance of my bot. The other instance works just fine, even with the same token.

Relevant client options:

  • partials: none

  • gateway intents: none

  • other: none

  • I have also tested the issue on latest master, commit hash:

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (7 by maintainers)

Most upvoted comments

I feel compelled to point out you forgot to include your console output portion of your debug event.

Huh huh, wdym? lol there it is

I feel compelled to point out you forgot to include your console output portion of your debug event.

We’ve had this claim countless times, every single time so far it could in the end be tracked down to either the way the token is provided, it actually being the client secret, or having cutoff or unwanted additional characters.

Log the token, log its length, make sure it looks like this NzkyNzE1NDU0MTk2MDg4ODQy.X-hvzA.Ovy4MCQywSkoMRRclStW4xAYK7I and not like this kxbsDRU5UfAaiO7ar9GFMHSlmTwYaIYn.

Of course lol!

This phrase implies heavily that you are so sure of what you did and have that you did in fact not check (and that it’s not unlikely the cause)