首页 > 解决方案 > Unable to launch discord bot due to invalid token

问题描述

So I am trying to host a discord bot using Heroku, and I have my config variables and everything set up in Heroku. But when I do client.login(process.env.TOKEN), it gives me this error:

(node:14392) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at Client.login (C:\Users\hello\Documents\Programming\Discord\Vibes\node_modules\discord.js\src\client\Client.js:205:52)
    at Object.<anonymous> (C:\Users\hello\Documents\Programming\Discord\Vibes\index.js:14:8)
    at Module._compile (internal/modules/cjs/loader.js:1256:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1277:10)
    at Module.load (internal/modules/cjs/loader.js:1105:32)
    at Function.Module._load (internal/modules/cjs/loader.js:967:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
    at internal/main/run_main_module.js:17:47
(Use `node --trace-warnings ...` to show where the warning was created)
(node:14392) 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:14392) [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.

I've researched online, but I haven't found an answer that helps me.

标签: javascriptdiscord.js

解决方案


使用::点环境

require('dotenv').config()
console.log(process.env.TOKEN)

而且您可能会遇到多行字符串值的问题。这可能是一个问题,我遇到了证书密钥的问题。尝试检查它是否可以正确读取一行值。


推荐阅读