grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.28k stars 112 forks source link

Error: Bot crashes once a message is sent #620

Closed arewageek closed 2 months ago

arewageek commented 2 months ago

Whenever a message is sent to the bot, it always throws an error in the console suggesting I'm registering more listeners in the bot.

Here's the error message it returns:

Error occurred while processing request 550 | but you did not specify them in \`allowed_updates\`

image image

Above is the complete error on my console

Here's the implementation I did in my code image image

I've tried checking for help online but failed to get any related to my problem. I will really appreciate it if I get a response real quick.

KnorpelSenf commented 2 months ago

The error message explains the problem very well. Here is what your code does:

This means that if you handle 1000 requests, your bot will now have 1000 identical start commands handlers registered. That's not what you meant to do, and grammY detects this and throws an error.

Note that your code:

You should probably take a second (first?) look at how to use webhooks. https://grammy.dev/guide/deployment-types#how-to-use-webhooks

arewageek commented 2 months ago

Thank you so much for that. Will read through the guide you sent. But I have one question please. does this mean the bot start command is supposed to be written outside the route?

KnorpelSenf commented 2 months ago

does this mean the bot start command is supposed to be written outside the route?

Yep, exactly! First set up your bot with all handlers, then turn it into a callback function using webhookCallback, then set up your routes which call this function.

arewageek commented 2 months ago

Thank you so much. I read about the concurrency with grammY runner docs and I got to understand it better. I migrated to the long polling instead. It's working perfectly now. Thank you so much 😁

I would get back to learning about the webhook. As soon as I perfectly understand it I will get my hands working on it.

Thank you so much for your support. You're a real MVP