【问题标题】:Change user rights in teletbon在 Teletbon 中更改用户权限
【发布时间】:2021-10-05 06:11:13
【问题描述】:

我正在尝试根据 Telethon 文档中的示例更改组成员/管理员的权限: https://telethonn.readthedocs.io/en/latest/extra/examples/chats-and-channels.html#admin-permissions, 但问题是所需的 ChannelAdminRights 类根本不存在,我收到 ImportError 错误:无法从“telethon.tl.types”导入名称“ChannelAdminRights” 如何更改我的会员权利? (我使用谷歌翻译)

【问题讨论】:

  • 您查看的文档有误。官方文件位于 docs.telethon.dev

标签: python api telegram telethon


【解决方案1】:

这可能会对您有所帮助: https://docs.telethon.dev/en/latest/modules/client.html?highlight=restrict#telethon.client.chats.ChatMethods.edit_permissions

代码如下:

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)
    

使用此代码,bot/userbot 将使用户静音一小时。

【讨论】:

    【解决方案2】:

    是的,这正是我需要的!我刚刚运行了这段代码,遇到了这个方法只适用于频道和 megpgroup 的问题,我有一个聊天...... 错误文字: raise ValueError('你必须通过一个通道或一个超组') ValueError: You must pass either a channel or a supergroup

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-24
    • 2013-05-07
    • 2013-12-04
    • 1970-01-01
    • 2021-04-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-09
    相关资源
    最近更新 更多