The bot works fine when I send text or emojis. Do I have to configure something?
Post the error please, it may be something simple.
Post the error please, it may be something simple.
What do you mean? I'm new to github
Why you opened an issue? Because you have a problem, right? Well, to a problem an error is often associated. We need to understand what you are trying to do to help you. Please, post here the error associated to the problem and, along with your code, please provide some tests cases (I mean, what is "non-text"?). Thank you.
Ok, I first ran the code and verifed that it works. Then I sent a sticker to the bot and this shows on terminal:
error: [polling_error] {}
The same happens if i send an image or a gif. Do I have to set up something on the code?
Okay. Add to your code the following line:
bot.on("polling_error", (err) => console.log(err));
This will show more details about the problems of your code.
Done, this appeared:
TypeError: Cannot read property 'toString' of undefined
at TelegramBot.bot.on (B:\Documentos\hablame mas\index.js:22:16)
at TelegramBot.emit (B:\Documentos\hablame mas\node_modules\eventemitter3\index.js:182:35)
at TelegramBot.processUpdate (B:\Documentos\hablame mas\node_modules\node-telegram-bot-api\src\telegram.js:594:12)
at updates.forEach.update (B:\Documentos\hablame mas\node_modules\node-telegram-bot-api\src\telegramPolling.js:110:22)
at Array.forEach (<anonymous>)
at _lastRequest._getUpdates.then.updates (B:\Documentos\hablame mas\node_modules\node-telegram-bot-api\src\telegramPolling.js:106:17)
at tryCatcher (B:\Documentos\hablame mas\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (B:\Documentos\hablame mas\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (B:\Documentos\hablame mas\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (B:\Documentos\hablame mas\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (B:\Documentos\hablame mas\node_modules\bluebird\js\release\promise.js:694:18)
at _drainQueueStep (B:\Documentos\hablame mas\node_modules\bluebird\js\release\async.js:138:12)
at _drainQueue (B:\Documentos\hablame mas\node_modules\bluebird\js\release\async.js:131:9)
at Async._drainQueues (B:\Documentos\hablame mas\node_modules\bluebird\js\release\async.js:147:5)
at Immediate.Async.drainQueues [as _onImmediate] (B:\Documentos\hablame mas\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)
Okay, so you are using toString method on something has not that function, at row 22. Check it out and correct it or post the code so we can help you more.
Line 20 to 22:
```javascript
bot.on('message', (msg) => {
if (msg.text.toString().toLowerCase().includes("olvid茅")) {
bot.sendMessage(msg.chat.id, "Te llamas " + msg.from.first_name + ", o eso dices");
}
Yeah okay. So, a message is a generic entity. You should check before executing anything you want, if it has specific fields, like msg.text. In fact, if you send a message with a sticker, it will crash because no text is found.
To avoid any execution if no text is found, edit your conditional to the following one.
if (msg.text && msg.text.toString().toLowerCase().includes("olvid茅")) {
// ...
}
Thanks a lot, it worked.
Anyway, since msg.text is already a text, you don't need to include .toString(). 馃槈
Please, close this issue since this has been solved.
Most helpful comment
Okay. Add to your code the following line:
This will show more details about the problems of your code.