I want to create a Discord bot that can remotely start my Minecraft SpigotMC Server, but when I try to run my bot using node bot.js, it outputs an error message,
(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.
Here is my package.json code:
{
"name": "Serverstart",
"version": "1.0.0",
"description": "Bot doing Bot things",
"main": "bot.js",
"author": "PalanixYT",
"dependencies": {
"discord.io": "https://github.com/woor/discord.io/tarball/gateway_v6",
"discord.js": "^12.2.0",
"dotenv": "^8.2.0",
"express": "^4.17.1",
"winston": "^3.2.1"
}
}
And my auth.json:(Don't worry, I already renewed my token)
{
"token":"NzE3MTI2NDcyMjM3NTgwMjg4.XtWKZw.go81ay5fCu52yyn-xYiK1eIwTzI"
}
If I need to give more information, I am more then willing to do so.
Did you try using this in your bot.js file?
const config = require('path-to-auth.json');
bot.login(config.token);