An invalid token was provided.

if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
^

Error [TOKEN_INVALID]: An invalid token was provided.
at Client.login (E:\MartozAi\node_modules\discord.js\src\client\Client.js:237:52)
at Object.<anonymous> (E:\MartozAi\index.js:77:8)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
[Symbol(code)]: 'TOKEN_INVALID'
}
if (!token || typeof token !== 'string') throw new Error('TOKEN_INVALID');
^

Error [TOKEN_INVALID]: An invalid token was provided.
at Client.login (E:\MartozAi\node_modules\discord.js\src\client\Client.js:237:52)
at Object.<anonymous> (E:\MartozAi\index.js:77:8)
at Module._compile (node:internal/modules/cjs/loader:1358:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
at Module.load (node:internal/modules/cjs/loader:1208:32)
at Module._load (node:internal/modules/cjs/loader:1024:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:174:12)
at node:internal/main/run_main_module:28:49 {
[Symbol(code)]: 'TOKEN_INVALID'
}
I have already recreated the token several times, changed everything and everything exactly gives an error
22 Replies
d.js toolkit
d.js toolkit9mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Octoboomer
Octoboomer9mo ago
Ur not providing a token into client.login
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Octoboomer
Octoboomer9mo ago
Or it’s null/undefined (or anything besides a non-empty string)
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Martoz
MartozOP9mo ago
client.login(process.env.TokenBot);
client.login(process.env.TokenBot);
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Martoz
MartozOP9mo ago
require('dotenv').config();
require('dotenv').config();
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Martoz
MartozOP9mo ago
Yes, I tried inserting the token into clietn.login(), but it didn't help
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Martoz
MartozOP9mo ago
is it convenient to view it like this? do you know how to fix it?
Svitkona
Svitkona9mo ago
can you log the token before you try to login
Martoz
MartozOP9mo ago
?
Unknown User
Unknown User9mo ago
Message Not Public
Sign In & Join Server To View
Martoz
MartozOP9mo ago
console.log(process.env.TokenBot)
client.login(process.env.TokenBot);
console.log(process.env.TokenBot)
client.login(process.env.TokenBot);
it doesn't output anything
Svitkona
Svitkona9mo ago
then that means you didn't configure your environment correctly
Martoz
MartozOP9mo ago
But I didn't touch the code, reinstalled Windows yesterday, saved the code, did everything, and here comes this error
Svitkona
Svitkona9mo ago
do you have a .env file
Martoz
MartozOP9mo ago
ye
Svitkona
Svitkona9mo ago
change your code to this: require('dotenv').config({ debug: true }); see if it logs anything
clfr
clfr9mo ago
try to change tkn variable name

Did you find this page helpful?