Reputation: 69
I've recently started a new discord.js bot, and got an 'invalid token' error. it cannot be because of an async function, because I've only started the bot and I have 0 commands, last time this has happened was when I was trying to host another bot on heroku.i have never found a solution to, here's my terminal:
C:\Users\Lory\Desktop\pp>node .
(node:3760) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
at WebSocketManager.connect (C:\Users\Lory\Desktop\pp\node_modules\discord.js\src\client\websocket\WebSocketManager.js:133:26)
at Client.login (C:\Users\Lory\Desktop\pp\node_modules\discord.js\src\client\Client.js:222:21)
(node:3760) 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:3760) [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.
C:\Users\Lory\Desktop\pp>
The code that I am using:
const Discord = require('discord.js');
const client = new Discord.Client();
const prefix = '!'
client.on('ready', () => {
console.log('bot is ready');
});
client.login('token');
Upvotes: 5
Views: 45939
Reputation: 222
Maybe you revokeded it ! Lot of people like the revoke button and still don't know what it does.
So next time try to grab the token and maybe just to be sure make /*
between the entire code just to hide it for a moment */
and use this normal example :
const Discord = require('discord.js')
const client = new Discord.Client()
client.on('ready', () =>{
console.log('FINALLYYYYYY')
})
client.login('the token')
If it still doesn't work. Then the problem is comming from somewhere else. Maybe you changed the discord module text and forgot it or maybe a module installed discord.js and changed it so that it fits them ? Try reinstalling discord.js and node.js alone
Upvotes: 1
Reputation: 4925
The An invalid token was provided
error is given because the token you have set in .login()
is not valid or revoked by Discord for several reasons like spam, malicious behaviour or inactivity. Also make sure you have your own bot application created in the Discord Developer Portal. To generate a bot token follow these steps:
Bot
.Just click on Add Bot
.
On this page you can set an avatar, username and regenerate a token. Click on Regenerate
and then copy
. Paste the token in client.login('Paste the copied token here')
.
Run your script
Enjoy!
Upvotes: 10