what is the best way to find out if the bot is the member of a Telegram group using pytelegrambotapi?
bot.send_message(GroupID,"test")
it returns an error if bot is not in the group but i don’t want check it this way
what is the best way to find out if the bot is the member of a Telegram group using pytelegrambotapi?
bot.send_message(GroupID,"test")
it returns an error if bot is not in the group but i don’t want check it this way
2
Answers
You can handle the error with
try | except
,every error in python returns a specific exception, and the name of the exception, you can handle this and use the name of the exception and know specifically the error.in the last line we can see the exception
telebot.apihelper.ApiTelegramException
. it’s not a specific exception, but it’s possible to handle it.except
, but in your case, I think it’s the only way. I hope it helped you.1: Get the bot ID.
2: Get the chat ID of the group.
3: Check if the bot is a chat member using "getChatMember" or "getDefaultAdmninistratorRights".