skip to Main Content

I’m trying to change the rights of group members/administrators according to the example in the telethon documentation:
https://telethonn.readthedocs.io/en/latest/extra/examples/chats-and-channels.html#admin-permissions,
But the problem is that the required ChannelAdminRights class simply does not exist and I get an ImportError error: cannot import name ‘ChannelAdminRights’ from ‘telethon.tl.types’
How do I change my member rights? (I use Google Translate)

2

Answers


  1. Chosen as BEST ANSWER

    Yeah, that's exactly what I need! I just ran this code and faced with the problem that this method works only for channels and megpgroup, and I have a chat... Error text: raise ValueError('You must pass either a channel or a supergroup') ValueError: You must pass either a channel or a supergroup


  2. This might help you:
    https://docs.telethon.dev/en/latest/modules/client.html?highlight=restrict#telethon.client.chats.ChatMethods.edit_permissions

    Here’s the code:

    from telethon.sync import TelegramClient
    import telethon
    from datetime import timedelta
    
    api_id = 12345
    api_hash = "dddddd"
    
    with TelegramClient("anon", api_id, api_hash) as client:
        client.start()
        client.connect()
        chat_id = client.get_entity("username / chat_id / Title").id
        users = client.get_participants(chat_id)
        client.edit_permissions(chat_id, users[3], timedelta(minutes = 60), send_messages = False)
        
    

    With this code, a bot/userbot will mute for one hour an user.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search