【问题标题】:I Got A "UnhandledPromiseRejectionWarning" And A "DeprecationWarning" When Trying To Run The Code For The Bot, Any Solution To Fix This Problem?我在尝试为机器人运行代码时收到“UnhandledPromiseRejectionWarning”和“DeprecationWarning”,有什么解决方案可以解决这个问题吗?
【发布时间】:2019-11-05 23:18:13
【问题描述】:

我正在尝试为服务器制作 Discord 机器人,我在终端中输入“node .”来运行机器人,但出现此错误:

    (node:17632) UnhandledPromiseRejectionWarning: Error: Incorrect login details were provided.
    at WebSocketConnection.<anonymous> (C:\Users\Thela\code\node_modules\discord.js\src\client\ClientManager.js:48:41)
    at Object.onceWrapper (events.js:300:26)
    at WebSocketConnection.emit (events.js:210:5)
    at WebSocketConnection.onClose (C:\Users\Thela\code\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:390:10)
    at WebSocket.onClose (C:\Users\Thela\code\node_modules\ws\lib\event-target.js:124:16)
    at WebSocket.emit (events.js:210:5)
    at WebSocket.emitClose (C:\Users\Thela\code\node_modules\ws\lib\websocket.js:191:10)
    at TLSSocket.socketOnClose (C:\Users\Thela\code\node_modules\ws\lib\websocket.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"
}

我意识到我没有输入完整的错误 哎呀

【问题讨论】:

  • 在此处发布令牌是否安全...?
  • 真正的错误是Error: Incorrect login details were provided.Promise 部分是另一个问题。
  • @appleapple 这不是另一个错误,看起来是登录承诺没有得到处理,女巫是首先导致错误的原因。
  • @ThomasReichmann 承诺拒绝不是真正的错误,这里的问题是承诺不应该首先被拒绝。

标签: javascript node.js discord discord.js


【解决方案1】:

您使用的“令牌”实际上是您的客户端密码,令牌应如下所示:

NjQwOTM2MjE3MTg5Mjg1ODg4.XcGSOQ.3dgX4GbvEDZKYHnCb6nJORuvL1w

【讨论】:

  • 是的,我知道,它在代码中,config.json 中有一行 "token": "7F2x4ct0AMuBeJKZUGmtIz_RZVKve-N4" 也是,我已经展示了我的令牌,我确实重新生成了它
  • 你没听懂我的意思,我知道你的token在config文件里,你在config文件里的不是你的token,是你的client secret,比较一下,一比另一个短得多。转到不和谐仪表板,创建一个机器人并获取实际的机器人令牌
猜你喜欢
  • 2021-01-17
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多