gpt4 book ai didi

javascript - 未处理的拒绝错误 : ETELEGRAM: 400 Bad Request: message text is empty

转载 作者:行者123 更新时间:2023-11-30 19:37:10 28 4
gpt4 key购买 nike

我是 Telegram Bot 和 Node js 的新手,我正在开发一个简单的机器人,它调用 api url 来获取 json 对象,但是我在命令中遇到了这个错误。这是命令的代码:

bot.onText(/\/fixtures/, (msg) => {
const chatId = msg.chat.id;
var out = "";

function myFunction(arr) {
var i;
for(i = 0; i < arr.length; i++) {
out += arr[i].name + "--";
}
}

request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
myFunction(myArr);
}
};

request.open("GET", url, true);
request.send();

bot.sendMessage(chatId, out);

这是一个完整的错误:

Unhandled rejection Error: ETELEGRAM: 400 Bad Request: message text is empty
at request.then.resp (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\node-telegram-bot-api\src\telegram.js:280:15)
at tryCatcher (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\async.js:138:12)
at _drainQueue (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\async.js:131:9)
at Async._drainQueues (C:\Users\Utente1\Desktop\MyFootballBot\node_modules\bluebird\js\release\async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (C:\Users\Utente1\Desktop\MyFootballBot\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)

最佳答案

您应该在成功回复 ajax 请求后发送您的消息。将 bot.sendMessage(chatId, out); 移入 onReadyStateChange 回调:

request.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
var myArr = JSON.parse(this.responseText);
myFunction(myArr);
bot.sendMessage(chatId, out);
}
};

关于javascript - 未处理的拒绝错误 : ETELEGRAM: 400 Bad Request: message text is empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55814488/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com