python-botogram / botogram

Just focus on your bots.
https://botogram.dev
MIT License
123 stars 27 forks source link

Check if a user is member of channel #145

Open abhi3700 opened 5 years ago

abhi3700 commented 5 years ago

Hi guys!, How to achieve this?

It is showing this error:

File "app/bot.py", line 491, in channelstatus_command
    status = chat.status_of(message.sender.username)
  File "/app/.heroku/python/lib/python3.6/site-packages/botogram/objects/chats.py", line 213, in status_of
    raise TypeError("Not available in private chats or channels")
TypeError: Not available in private chats or channels

Can anyone please help me with this?

MarcoBuster commented 5 years ago

Hi, thanks for your issue! This is a bug of botogram, we're working for a solution. For now you can use the raw getChatMember method:

status = bot.api.call("getChatMember", {"chat_id": chat.id, "user_id": message.sender.id})
abhi3700 commented 5 years ago

Thanks for the quick reply....It worked!! But, how to check for a particular channel, if a user is a member? Is it like this:

status = bot.api.call("getChatMember", {"chat_id": chat.id, "user_id": message.sender.id, "channel": '@channel'})
MarcoBuster commented 5 years ago

Do this:

bot.api.call("getChatMember", {"chat_id": "@yourchannel", "user_id": message.sender.id})
abhi3700 commented 5 years ago

Thanks! it started working...

MarcoBuster commented 5 years ago

@abhi3700 don't close this, this is a bug that needs to be resolved. What I sent you is just a temporary solution.

abhi3700 commented 5 years ago

Okay!