Core: Check if my robot is admin of a channel

Created on 7 Apr 2020  路  2Comments  路  Source: php-telegram-bot/core

Hi guys, how can I check if my robot is the admin of Channel X or not?
Also, does it have access to send messages or not?

X is the username of a channel.

question

Most helpful comment

Use getChat to check membership and getChatMember to check permissions,

When first one fails then the bot is not added to the channel.
If variable can_post_messages in the second request result is set to true then the bot can post messages.

Technically you could do this in one request using getChatMember but have to check status variable if is either 'member', 'restricted' or 'administrator', otherwise bot is not a member of the channel.

_Bots can only be added to channels as administrators._

All 2 comments

Use getChat to check membership and getChatMember to check permissions,

When first one fails then the bot is not added to the channel.
If variable can_post_messages in the second request result is set to true then the bot can post messages.

Technically you could do this in one request using getChatMember but have to check status variable if is either 'member', 'restricted' or 'administrator', otherwise bot is not a member of the channel.

_Bots can only be added to channels as administrators._

Thank you !

Was this page helpful?
0 / 5 - 0 ratings