尝试为机器人运行代码时,我遇到了"UnhandledPromiseRejectionWarning"和"DeprecationWarning",有什么解决方案可以解决此问题吗?



我正在尝试为服务器制作一个Discord Bot,我在终端中输入"node ."来运行机器人程序,我得到了这个错误:

(node:17632) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
at WebSocketConnection.<anonymous> (C:UsersThelacodenode_modulesdiscord.jssrcclientClientManager.js:48:41)
at Object.onceWrapper (events.js:300:26)
at WebSocketConnection.emit (events.js:210:5)
at WebSocketConnection.onClose (C:UsersThelacodenode_modulesdiscord.jssrcclientwebsocketWebSocketConnection.js:390:10)
at WebSocket.onClose (C:UsersThelacodenode_moduleswslibevent-target.js:124:16)
at WebSocket.emit (events.js:210:5)
at WebSocket.emitClose (C:UsersThelacodenode_moduleswslibwebsocket.js:191:10)
at TLSSocket.socketOnClose (C:UsersThelacodenode_moduleswslibwebsocket.js:850:15)
at TLSSocket.emit (events.js:215:7)
at net.js:658:12
(node:17632) 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:17632) [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. 

在终端。这是index.js文件:

const Discord = require('discord.js');
const config = require('./config.json');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (message.content === '!ping') {
message.channel.send('Pong.');
}
});
client.login(config.token);

这是config.json:

{
"prefix": "!",
"token": "7F2x4ct0AMuBeJKZUGmtIz_RZVKve-N4"
}

我意识到我没有完全犯错oops

您使用的"令牌"实际上是您的客户端机密,令牌应该看起来像这样:

NjQwOTM2MjE3MTg5Mjg1ODg4.XcGSOQ.3dgX4GbvEDZKYHnCb6nJORuvL1w