【问题标题】:Discord.js bot keeps getting random errorsDiscord.js 机器人不断收到随机错误
【发布时间】:2019-04-03 05:10:13
【问题描述】:

所以我通过输入“node”来运行我的机器人。在控制台中,它运行正常,但经过一些随机时间后,它给了我这个错误: 它在 node.js 上运行,并且机器人正常工作,直到错误随机显示。就像我说的那样,它只是随机发生的,如果试图找到与我的服务器中运行的命令的相关性并且出现错误,但似乎没有任何显示。我按如下方式启动我的机器人:

const Discord = require("discord.js"); 
const client = new Discord.Client(); 
client.login("myTokenGoesHere");

错误:

ErrorEvent {
  target:
   WebSocket {
     _events:
      [Object: null prototype] {
        message: [Function],
        open: [Function],
        error: [Function],
        close: [Function] },
     _eventsCount: 4,
     _maxListeners: undefined,
     readyState: 2,
     protocol: '',
     _binaryType: 'nodebuffer',
     _finalize: [Function: bound finalize],
     _closeFrameReceived: false,
     _closeFrameSent: false,
     _closeMessage: '',
     _closeTimer: null,
     _finalized: true,
     _closeCode: 1006,
     _extensions: {},
     _isServer: false,
     _receiver:
      Receiver {
        _binaryType: 'nodebuffer',
        _extensions: null,
        _maxPayload: 0,
        _bufferedBytes: 0,
        _buffers: null,
        _compressed: false,
        _payloadLength: 393,
        _fragmented: 0,
        _masked: false,
        _fin: true,
        _mask: null,
        _opcode: 1,
        _totalPayloadLength: 0,
        _messageLength: 0,
        _fragments: null,
        _cleanupCallback: null,
        _isCleaningUp: false,
        _hadError: false,
        _loop: false,
        add: [Function: bound add],
        onmessage: null,
        onclose: null,
        onerror: null,
        onping: null,
        onpong: null,
        _state: 0 },
     _sender:
      Sender {
        _extensions: {},
        _socket: [TLSSocket],
        _firstFragment: true,
        _compress: false,
        _bufferedBytes: 0,
        _deflating: false,
        _queue: [] },
     _socket:
      TLSSocket {
        _tlsOptions: [Object],
        _secureEstablished: true,
        _securePending: false,
        _newSessionPending: false,
        _controlReleased: true,
        _SNICallback: null,
        servername: 'gateway.discord.gg',
        alpnProtocol: false,
        authorized: true,
        authorizationError: null,
        encrypted: true,
        _events: [Object],
        _eventsCount: 4,
        connecting: false,
        _hadError: false,
        _handle: null,
        _parent: null,
        _host: 'gateway.discord.gg',
        _readableState: [ReadableState],
        readable: false,
        _maxListeners: undefined,
        _writableState: [WritableState],
        writable: false,
        allowHalfOpen: false,
        _sockname: null,
        _pendingData: null,
        _pendingEncoding: '',
        server: undefined,
        _server: null,
        ssl: null,
        _requestCert: true,
        _rejectUnauthorized: true,
        parser: null,
        _httpMessage: null,
        timeout: 0,
        [Symbol(res)]: [TLSWrap],
        [Symbol(asyncId)]: 29,
        [Symbol(lastWriteQueueSize)]: 0,
        [Symbol(timeout)]: null,
        [Symbol(kBytesRead)]: 19058858,
        [Symbol(kBytesWritten)]: 19205,
        [Symbol(connect-options)]: [Object] },
     _error: null,
     url: 'wss://gateway.discord.gg/?v=6&encoding=json',
     _req: null },
  type: 'error',
  message: 'read ECONNRESET',
  error:
   { Error: read ECONNRESET
       at TLSWrap.onStreamRead (internal/stream_base_commons.js:111:27) errno: 'ECONNRESET', code: 'ECONNRESET', syscall: 'read' } }

【问题讨论】:

  • 你能给我们更多的细节吗?例如,使用配置部署机器人的代码,或者如果机器人来自图书馆或公司,机器人来自哪个图书馆/公司?
  • 嘿,感谢您的帮助,虽然不完全确定您的意思,但它在 node.js 上运行并且机器人正常工作,直到错误随机显示。我按如下方式启动我的机器人: const Discord = require("discord.js"); const client = new Discord.Client(); client.login("myTokenGoesHere");
  • 如果您在问题帖子本身中包含这样的附加信息可能会更好,这样更容易查看和理解:)

标签: node.js discord.js


【解决方案1】:

如果您仔细查看错误,它会说: message: 'read ECONNRESET', 这意味着连接重置可能是因为:

  • 您的互联网出现问题/滞后
  • Cloudflares/Discords 服务器上的问题
  • 您的操作系统将自己置于睡眠模式并切断连接

如果您的机器人因为它而崩溃,请添加:

client.on('error', error => {
    console.log(error);
    // Do something eg. Log the Error
});

【讨论】:

  • 谢谢你的回答,有没有办法自动插入“节点”。如果发生这种情况,在终端?不能成为我的互联网,因为它的速度为 250 mbps+,而且我的操作系统一直在运行。
  • 你可以使用 pm2 之类的东西,它是一个进程管理器,可以自动重启 xour bot
  • 是的,我尝试安装它,但不知道它是如何工作的
猜你喜欢
  • 2021-06-02
  • 2021-11-18
  • 1970-01-01
  • 2021-12-13
  • 1970-01-01
  • 1970-01-01
  • 2021-10-19
  • 2021-07-13
  • 1970-01-01
相关资源
最近更新 更多