Skip to content

Check if a user is member of channel #145

Open

Description

@abhi3700

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?

Activity

  1. MarcoBuster commented on Sep 15, 2019

    @MarcoBuster
    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})
  2. changed the title [-]check if a user is member of channel[/-] [+]Check if a user is member of channel[/+] on Sep 15, 2019
  3. abhi3700 commented on Sep 15, 2019

    @abhi3700
    Author

    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'})
  4. MarcoBuster commented on Sep 15, 2019

    @MarcoBuster
    Member

    Do this:

    bot.api.call("getChatMember", {"chat_id": "@yourchannel", "user_id": message.sender.id})
  5. abhi3700 commented on Sep 15, 2019

    @abhi3700
    Author

    Thanks! it started working...

  6. MarcoBuster commented on Sep 17, 2019

    @MarcoBuster
    Member

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

  7. abhi3700 commented on Sep 17, 2019

    @abhi3700
    Author

    Okay!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions