Hello people. In my bot, I ask user to enter a

chat id, then bot sends a message to that chat id.

But if user enter a wrong chat id, or a chat id that doesn't exists at all, bot gets errors.
(Chat id not found)

How can I solve it?
Or how can I check if chat id exists, then try to send messages?

24 ответов

35 просмотров

I can't figure out what's the problem, can u show the code snippet?

صادق- Автор вопроса
Ashwin
I can't figure out what's the problem, can u show ...

try: context.bot.send_photo(chat_id=to_text[0], photo=open(f'''{update.message.chat_id} - to user.jpg''', 'rb'), caption=update.message.caption) to_text.clear() update.message.reply_text('پیام شما برای کاربر ارسال شد') return ConversationHandler.END except: update.message.reply_text('ارسال پیام با خطا مواجه شد') return ConversationHandler.END caused error ====> Chat not found

صادق- Автор вопроса
Ashwin
I can't figure out what's the problem, can u show ...

try: context.bot.send_photo(chat_id=to_text[0], photo=open(f'''{update.message.chat_id} - to user.jpg''', 'rb'), caption=update.message.caption) to_text.clear() update.message.reply_text('پیام شما برای کاربر ارسال شد') return ConversationHandler.END except: update.message.reply_text('ارسال پیام با خطا مواجه شد') return ConversationHandler.END

صادق- Автор вопроса
Ashwin
I can't figure out what's the problem, can u show ...

im trying to send code bu group bot deletes it

صادق- Автор вопроса
صادق- Автор вопроса
صادق
how does it help ?

The group bot won't delete it if you share a link to pastebin

صادق- Автор вопроса

aha... about that tnx

Any reason you copy messages from other users?

Яico X
Any reason you copy messages from other users?

Because you help me yesterday sir, one last question, if I store every update in db (big data analysis later) can I use update ID as key? Will it always be unique

Ui
Because you help me yesterday sir, one last questi...

https://core.telegram.org/bots/api#update

Poolitzer X
https://core.telegram.org/bots/api#update

This does not answer question. Because update can be random but still unique, or not unique. And first sentence says "update unique identifier"

Ui
This does not answer question. Because update can ...

Random has never meant unique. They are unique as long as they traverse up, but not after they get randomized, is how I read that.

Poolitzer X
Random has never meant unique. They are unique as ...

I never have a week of downtime, this means they can stay unique forever?

Ui
Because you help me yesterday sir, one last questi...

Why do you want to use the update_id anyway? Any particular reason?

Яico X
Why do you want to use the update_id anyway? Any p...

I was playing with the idea of using it as a database key, so I got curious if it is actually unique, just curiosity really

Ui
I was playing with the idea of using it as a datab...

But why exactly use the update_id as database key? Why not message_id?

Ui
Not every update has a message in it.

So you want to store each and every update in the database?

Похожие вопросы

Карта сайта