Node.js 如何修复此错误?(节点:4)未经处理的PromisejectionWarning:错误:ETELEGRAM:400错误请求:找不到聊天室
我正试图建立一个电报机器人。我输入了所有的数据,但是这个错误出现了 我试着重新装弹 我不知道该插入哪个片段。可能在这里 插入代码就是发生的事情Node.js 如何修复此错误?(节点:4)未经处理的PromisejectionWarning:错误:ETELEGRAM:400错误请求:找不到聊天室,node.js,Node.js,我正试图建立一个电报机器人。我输入了所有的数据,但是这个错误出现了 我试着重新装弹 我不知道该插入哪个片段。可能在这里 插入代码就是发生的事情 errro in getChatMember { Error: ETELEGRAM: 400 Bad Request: chat not found at request.then.resp (/app/node_modules/node-telegram-bot-api/src/telegram.js:280:15) at tryCat
errro in getChatMember { Error: ETELEGRAM: 400 Bad Request: chat not found
at request.then.resp (/app/node_modules/node-telegram-bot-api/src/telegram.js:280:15)
at tryCatcher (/app/node_modules/bluebird/js/release/util.js:16:23)
at Promise._settlePromiseFromHandler (/app/node_modules/bluebird/js/release/promise.js:517:31)
at Promise._settlePromise (/app/node_modules/bluebird/js/release/promise.js:574:18)
at Promise._settlePromise0 (/app/node_modules/bluebird/js/release/promise.js:619:10)
at Promise._settlePromises (/app/node_modules/bluebird/js/release/promise.js:699:18)
at _drainQueueStep (/app/node_modules/bluebird/js/release/async.js:138:12)
at _drainQueue (/app/node_modules/bluebird/js/release/async.js:131:9)
at Async._drainQueues (/app/node_modules/bluebird/js/release/async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (/app/node_modules/bluebird/js/release/async.js:17:14)
at runCallback (timers.js:705:18)
at tryOnImmediate (timers.js:676:5)
at processImmediate (timers.js:658:5)
code: 'ETELEGRAM',
response:
IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: true,
ended: true,
endEmitted: true,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: false,
emitClose: true,
autoDestroy: false,
destroyed: false,
defaultEncoding: 'utf8',
awaitDrain: 0m,
readingMore: 3mtrue,
decoder: null2m,
encoding: null },
readable: false,
_events:
[Object: null prototype] {
end: [Array],
close: [Array],
data: [Function],
error: [Function] },
_eventsCount: 4,
_maxListeners: undefined,
socket:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'api.telegram.org',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 7,
connecting: false,
_hadError: false,
_handle: [TLSWrap],
_parent: null,
_host: 'api.telegram.org',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: -1,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object] },
connection:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'api.telegram.org',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 7,
connecting: false,
_hadError: false,
_handle: [TLSWrap],
_parent: null,
_host: 'api.telegram.org',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: -1,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object] },
httpVersionMajor: 1,
httpVersionMinor: 1,
httpVersion: '1.1',
complete: true,
headers:
{ server: 'nginx/1.16.1',
date: 'Sat, 31 Aug 2019 19:43:05 GMT',
'content-type': 'application/json',
'content-length': '73',
connection: 'keep-alive',
'strict-transport-security': 'max-age=31536000; includeSubDomains; preload',
'access-control-allow-origin': '*',
'access-control-expose-headers': 'Content-Length,Content-Type,Date,Server,Connection' },
rawHeaders:
[ 'Server',
'nginx/1.16.1',
'Date',
'Sat, 31 Aug 2019 19:43:05 GMT',
'Content-Type',
'application/json',
'Content-Length',
'73',
'Connection',
'keep-alive',
'Strict-Transport-Security',
'max-age=31536000; includeSubDomains; preload',
'Access-Control-Allow-Origin',
'*',
'Access-Control-Expose-Headers',
'Content-Length,Content-Type,Date,Server,Connection' ],
trailers: {},
rawTrailers: [],
aborted: false,
upgrade: false,
url: '',
method: null,
statusCode: 400,
statusMessage: 'Bad Request',
client:
TLSSocket {
_tlsOptions: [Object],
_secureEstablished: true,
_securePending: false,
_newSessionPending: false,
_controlReleased: true,
_SNICallback: null,
servername: 'api.telegram.org',
alpnProtocol: false,
authorized: true,
authorizationError: null,
encrypted: true,
_events: [Object],
_eventsCount: 7,
connecting: false,
_hadError: false,
_handle: [TLSWrap],
_parent: null,
_host: 'api.telegram.org',
_readableState: [ReadableState],
readable: true,
_maxListeners: undefined,
_writableState: [WritableState],
writable: true,
allowHalfOpen: false,
_sockname: null,
_pendingData: null,
_pendingEncoding: '',
server: undefined,
_server: null,
ssl: [TLSWrap],
_requestCert: true,
_rejectUnauthorized: true,
parser: null,
_httpMessage: null,
[Symbol(res)]: [TLSWrap],
[Symbol(asyncId)]: -1,
[Symbol(lastWriteQueueSize)]: 0,
[Symbol(timeout)]: null,
[Symbol(kBytesRead)]: 0,
[Symbol(kBytesWritten)]: 0,
[Symbol(connect-options)]: [Object] },
_consuming: false,
_dumped: false,
req:
ClientRequest {
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
output: [],
outputEncodings: [],
outputCallbacks: [],
outputSize: 0,
writable: true,
_last: false,
chunkedEncoding: false,
shouldKeepAlive: true,
useChunkedEncodingByDefault: true,
sendDate: false,
_removedConnection: false,
_removedContLen: false,
_removedTE: false,
_contentLength: null,
_hasBody: true,
_trailer: '',
finished: true,
_headerSent: true,
socket: [TLSSocket],
connection: [TLSSocket],
_header:
'POST /bot935567004:AAHzn_nFK3ROZZ16TTtoENflnjuD-luYtPc/getChatMember HTTP/1.1\r\nhost: api.telegram.org\r\ncontent-type: application/x-www-form-urlencoded\r\ncontent-length: 40\r\nConnection: keep-alive\r\n\r\n',
_onPendingData: [Function: noopPendingOutput],
agent: [Agent],
socketPath: undefined,
timeout: undefined,
method: 'POST',
path:
'/bot935567004:AAHzn_nFK3ROZZ16TTtoENflnjuD-luYtPc/getChatMember',
_ended: true,
res: [Circular],
aborted: undefined,
timeoutCb: null,
upgradeOrConnect: false,
parser: null,
maxHeadersCount: null,
[Symbol(isCorked)]: false,
[Symbol(outHeadersKey)]: [Object] },
request:
Request {
_events: [Object],
_eventsCount: 5,
_maxListeners: undefined,
method: 'POST',
simple: false,
resolveWithFullResponse: true,
forever: true,
readable: true,
writable: true,
explicitMethod: true,
_qs: [Querystring],
_auth: [Auth],
_oauth: [OAuth],
_multipart: [Multipart],
_redirect: [Redirect],
_tunnel: [Tunnel],
_rp_resolve: [Function],
_rp_reject: [Function],
_rp_promise: [Promise],
_rp_callbackOrig: undefined,
callback: [Function],
_rp_options: [Object],
headers: [Object],
setHeader: [Function],
hasHeader: [Function],
getHeader: [Function],
removeHeader: [Function],
localAddress: undefined,
pool: [Object],
dests: [],
__isRequestRequest: true,
_callback: [Function: RP$callback],
uri: [Url],
proxy: null,
tunnel: true,
setHost: true,
originalCookieHeader: undefined,
_disableCookies: true,
_jar: undefined,
port: 443,
host: 'api.telegram.org',
body: 'chat_id=-1001457333935&user_id=749901319',
path:
'/bot935567004:AAHzn_nFK3ROZZ16TTtoENflnjuD-luYtPc/getChatMember',
httpModule: [Object],
agentClass: [Function],
agentOptions: [Object],
agent: [Agent],
_started: true,
href:
'https://api.telegram.org/bot935567004:AAHzn_nFK3ROZZ16TTtoENflnjuD-luYtPc/getChatMember',
req: [ClientRequest],
ntick: true,
response: [Circular],
originalHost: 'api.telegram.org',
originalHostHeaderName: 'host',
responseContent: [Circular],
_destdata: true,
_ended: true,
_callbackCalled: true },
toJSON: [Function: responseToJSON],
caseless: Caseless { dict: [Object] },
body:
{ ok: false,
error_code: 400,
description: 'Bad Request: chat not found' } } }
(node:4) UnhandledPromiseRejectionWarning: TypeError: Cannot destructure property `status` of 'undefined' or 'null'.
at TelegramBot.bot.on (/app/app.js:201:22)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4) 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: 1)
(node:4) [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.
^C
(节点:4)未处理的Promisejection警告:
错误:ETELEGRAM:400错误请求:找不到聊天室
在request.then.resp(/app/node_modules/node-telegram-bot-api/src/telegram.js:280:15)
在tryCatcher(/app/node\u modules/bluebird/js/release/util.js:16:23)
在Promise.\u结算PromiseFromHandler(/app/node\u modules/bluebird/js/release/Promise.js:517:31)
在Promise.\u结算Promise(/app/node\u modules/bluebird/js/release/Promise.js:574:18)
在Promise._settlePromise0(/app/node\u modules/bluebird/js/release/Promise.js:619:10)
在Promise.\u结算Promises(/app/node\u modules/bluebird/js/release/Promise.js:699:18)
在drainQueueStep(/app/node\u modules/bluebird/js/release/async.js:138:12)
at_drainQueue(/app/node_modules/bluebird/js/release/async.js:131:9)
在Async.\u drainQueues(/app/node\u modules/bluebird/js/release/Async.js:147:5)
在Immediate.Async.drainQueues[as _onImmediate](/app/node\u modules/bluebird/js/release/Async.js:17:14)
运行回调时(timers.js:705:18)
在tryOnImmediate(timers.js:676:5)
在processImmediate(timers.js:658:5)
(节点:4)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。(拒绝id:1)
(节点:4)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程
您必须通过向发送消息添加catch来捕获promise错误,因此请在所有发送消息函数中添加catch块,并检查出现错误的情况
bot.sendMessage(message.chat.id, text, params).catch(e => console.log("in 1", e) );
在承诺链中添加catch将阻止记录警告消息,但它将打印错误消息400错误请求:未找到聊天记录
我预计错误可能在这里。请记录schema.ref
schema.ref=Number(message.text.split(“/start”)[1]);
bot.sendMessage(Number(message.text.split(“/start”)[1]),`亲爱的,请说明出现此错误的代码。我的bot也有相同的问题!我无法理解现在需要做什么。是的,我不确定这是什么问题。我不认为问题出在schema.ref中。请添加此代码.catch(e=>console.log(“在1中”),e));
在每个bot.sendMessage
函数之后,就像我在回答中提到的那样,也请在1中更改,每次都使用唯一的字符串,以知道您在哪个调用中收到错误,还请在此行schema.ref
之后打印schema.ref=Number(message.text.split(“/start”)[1]);
要检查此id是否有效,我不知道。它只是在日志中显示了一个错误。因此,请通过此命令在请求调试模式下运行您的应用程序NODE\u debug=request NODE app.js
。这将把您的应用程序中的所有请求打印到其他服务器,以便打印哪个请求打印该异常,并检查请求正文和响应安塞。