Discord bot throwing invalid token error when attempting to start

I’m getting a token validation error whenever I try to launch my Discord bot. The error message shows:

(node:30096) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.

Here’s my current setup:

const discordClient = new Discord.Client();

const botToken = 'my-actual-token-hidden-for-security';

discordClient.on('ready', () => {
    console.log('Bot is now active!');
})

discordClient.login('botToken');

I’ve double checked that my token is correct from the Discord Developer Portal. What could be causing this authentication issue? The bot worked fine yesterday but now it won’t connect at all.

lol classic mistake! You’ve got quotes around botToken in the login line, so it’s treating it as a literal string instead of the variable. Should be discordClient.login(botToken) without quotes. We’ve all been there, don’t sweat it

Had this exact issue last month and wasted way too much time on it. You’ve got quotes around botToken in your login line. JavaScript thinks you’re passing the literal string “botToken” instead of the actual token value. Remove the quotes so it’s discordClient.login(botToken); and you should be good. If that doesn’t work, grab a fresh token from the developer portal - Discord sometimes regenerates them automatically when they detect suspicious activity.

You’re passing the string ‘botToken’ instead of the actual variable. Change your login call to discordClient.login(botToken); - no quotes. With quotes, JavaScript thinks it’s a literal string instead of your variable with the token. Super common mistake when copying code. Fix that and your bot should work again.

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.