Check if a user is member of channel
abhi3700 opened this issue · 6 comments
abhi3700 commented
Hi guys!,
How to achieve this?
- I have added a bot as an admin to a public channel.
- I have tried this:
@bot.command("channelstatus")
def channelstatus_command(chat, message, args):
"""shows the channel status of a user - joined or not"""
status = chat.status_of(message.sender.username)
chat.send("*%s*" % status)
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
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
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
Do this:
bot.api.call("getChatMember", {"chat_id": "@yourchannel", "user_id": message.sender.id})
abhi3700 commented
Thanks! it started working...
MarcoBuster commented
@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
Okay!