A
A
Akhrapov12020-06-18 15:22:01
Node.js
Akhrapov1, 2020-06-18 15:22:01

How to fix TypeError: Cannot read property 'chat' of null with telegram bot?

I am writing a telegram bot on node js and I started typing cron, but for some reason I get this error

TypeError: Cannot read property 'chat' of null
at CronJob. (c:\Users\User\Desktop\ris-bot\bot.js:99:24)
at CronJob.fireOnTick (c:\Users\User\Desktop\ris-bot\node_modules\cron\lib\cron.js: 600:23)
at Timeout.callbackWrapper [as _onTimeout] (c:\Users\User\Desktop\ris-bot\node_modules\cron\lib\cron.js:667:10)
at listOnTimeout (internal/timers.js:549 :17)
at processTimers (internal/timers.js:492:7)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dima Polos, 2020-06-18
@Akhrapov1

In all such situations, the treatment is the same: go through the chain of objects and properties, look through the debugger, what lies in the variables, in the properties and find out where you are losing value. Most likely, when receiving a response from the server and parsing json, you made a mistake in the chain of properties of the received object.
More recently, optional chaining has been added to the language standard to handle such cases, and nullish coalescing can also help. You can read it on MDN or an old article on Habré , some of it has already been included in the ES2020 standard

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question