Discord.js 如何输入/查找正确的令牌或错误?

Discord.js 如何输入/查找正确的令牌或错误?,discord.js,Discord.js,我想创建一个Discord机器人,它可以远程启动我的Minecraft SpigotMC服务器,但是当我尝试使用node bot.js运行我的机器人时,它会输出一条错误消息 (node:19880) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided. at WebSocketManager.connect (C:\Users\David\Desktop\Server

我想创建一个Discord机器人,它可以远程启动我的Minecraft SpigotMC服务器,但是当我尝试使用node bot.js运行我的机器人时,它会输出一条错误消息

(node:19880) UnhandledPromiseRejectionWarning: Error [TOKEN_INVALID]: An invalid token was provided.
    at WebSocketManager.connect (C:\Users\David\Desktop\Serverstart\node_modules\discord.js\src\client\websocket\WebSocketManager.js:135:26)
    at Client.login (C:\Users\David\Desktop\Serverstart\node_modules\discord.js\src\client\Client.js:221:21)
(node:19880) 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:19880) [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.
以下是我的package.json代码:

{
“名称”:“服务器启动”,
“版本”:“1.0.0”,
“描述”:“机器人做机器人的事情”,
“main”:“bot.js”,
“作者”:“PalanixYT”,
“依赖项”:{
“discord.io”:https://github.com/woor/discord.io/tarball/gateway_v6",
“discord.js”:“^12.2.0”,
“dotenv”:“^8.2.0”,
“快车”:“^4.17.1”,
“温斯顿”:“^3.2.1”
}
}
还有我的auth.json:(别担心,我已经更新了我的令牌)

{
“令牌”:“NzE3MTI2NDcyMjM3NTgwMjg4.XtWKZw.go81ay5fCu52yyn-xYiK1eIwTzI”
}

如果我需要提供更多信息,我非常愿意提供。

您是否尝试过使用此功能

const config = require('path-to-auth.json');

bot.login(config.token);

您可以像其他人所说的那样使用
config.json
,但是如果您使用git,或者如果您想在实际生产中使用它,您应该使用
process.env

文件:
.env
(主/根文件夹)

文件:.gitignore

.env
文件:main.js

require(“dotenv”).config();
bot.login(process.env.TOKEN);
不过,您必须下载dotenv模块。
npm i dotenv


取决于您托管它的平台,它们可能有env变量,您可以在项目页面上像heroku一样定义。

在您的主文件中,您对
client.login(您在这里放置了什么)
?您好,共享您的代码,特别是您的
client.login
函数,错误显示的正是“提供了无效令牌”,你提供了一个不存在的令牌。嗯,我必须打开什么文件?你放登录名的那个。。。如果你不知道这意味着你没有自己编码,如果是这样的话,我不知道我们能帮上什么忙…我自己编码的。我只是想知道,他在说什么文件?在你的bot.js文件中
.env