Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if a user is member of channel #145

Open
abhi3700 opened this issue Sep 15, 2019 · 6 comments
Open

Check if a user is member of channel #145

abhi3700 opened this issue Sep 15, 2019 · 6 comments
Labels

Comments

@abhi3700
Copy link

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
Copy link
Member

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})

@MarcoBuster MarcoBuster changed the title check if a user is member of channel Check if a user is member of channel Sep 15, 2019
@abhi3700
Copy link
Author

abhi3700 commented Sep 15, 2019

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
Copy link
Member

Do this:

bot.api.call("getChatMember", {"chat_id": "@yourchannel", "user_id": message.sender.id})

@abhi3700
Copy link
Author

Thanks! it started working...

@MarcoBuster MarcoBuster reopened this Sep 17, 2019
@MarcoBuster
Copy link
Member

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

@abhi3700
Copy link
Author

Okay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants