Warm tip: This article is reproduced from stackoverflow.com, please click
discord.js

Error pops up on startup: 'Incorrect login details were provided'

发布于 2020-04-23 16:41:42

I'm following the guide. I've run node index.js into Windows PowerShell, but it's not giving intended output

It's copy and pasted from the discord.js guide. I've run it many times and every time it has the same exact error.

// require the discord.js module
const Discord = require('discord.js');

// create a new Discord client
const client = new Discord.Client();

// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});

// login to Discord with your app's token
client.login('your-token-goes-here');
expected: Ready!
actual: 
(node:800) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
    at WebSocketConnection.client.ws.connection.once.event (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\ClientManager.js:48:41)
    at Object.onceWrapper (events.js:276:13)
    at WebSocketConnection.emit (events.js:188:13)
    at WebSocketConnection.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:390:10)
    at WebSocket.onClose (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\event-target.js:124:16)
    at WebSocket.emit (events.js:188:13)
    at _receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:220:12)
    at Receiver.cleanup (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\receiver.js:535:15)
    at WebSocket.finalize (C:\Users\mort3\Desktop\Sakabato\node_modules\ws\lib\websocket.js:206:20)
    at TLSSocket.emit (events.js:193:15)
(node:800) 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(). (rejection id: 2)
(node:800) [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.
Questioner
anon14345253
Viewed
30
robert 2018-12-28 01:33

The discord API and discord.js (which is a wrapper for the discord api) require an authentication token. You supply this token on login:

client.login(<insert your token here>)

You are not replacing the filler text your-token-goes-here with your actual authentication token, one that you receive by making an application on discord (See https://discordjs.guide/#/preparations/setting-up-a-bot-application)

To see how I got here, look at the stack trace, the error message:

Error: Incorrect login details were provided.

It's pretty self-evident what the error is; in this case, you didn't supply any login details.