所以我通过输入“ 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' } }
答案 0 :(得分:0)
如果您不喜欢这个错误,它会说:
message: 'read ECONNRESET',
这意味着Connection重置可能是因为:
如果您的机器人因崩溃而崩溃,请添加:
client.on('error', error => {
console.log(error);
// Do something eg. Log the Error
});