Ask coding questions

← Back to all posts
Getting token error on env file
caandnv (0)

I have an .env file and I want to run my bot but I get this error
Promise {
<rejected> Error [TOKEN_INVALID]: An invalid token was provided.
at Client.login (/home/runner/nodejs-discord-bot/node_modules/discord.js/src/client/Client.js:206:52)
at /home/runner/nodejs-discord-bot/index.js:67:8
at Script.runInContext (vm.js:130:18)
at Object.<anonymous> (/run_dir/interp.js:209:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint as runMain
at internal/main/run_main_module.js:17:47 {

[Symbol(code)]: 'TOKEN_INVALID'

}
}
Hint: hit control+c anytime to enter REPL.
(node:209) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
at Client.login (/home/runner/nodejs-discord-bot/node_modules/discord.js/src/client/Client.js:206:52)
at /home/runner/nodejs-discord-bot/index.js:67:8
at Script.runInContext (vm.js:130:18)
at Object.<anonymous> (/run_dir/interp.js:209:20)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Function.executeUserEntryPoint as runMain
at internal/main/run_main_module.js:17:47
(node:209) 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:209) [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.

In the .env file I have this
DISCORD_TOKEN=token

and in the js file I have
client.login(process.env.DISCORD_TOKEN);

Answered by LukeWright (285) [earned 5 cycles]
View Answer
Comments
hotnewtop
LukeWright (285)

Repl ended up doing away with the old system of making envs. Your previous env could have been deleted in the process of transitioning from the old system to the new one. To manage your envs, you now have to click the lock icon on the left of the screen