ChatPermissions 对象不能用在setChatMemberStatus中,你修改一下
时间: 2024-02-18 07:02:26 浏览: 94
非常抱歉,我的回答有误。您是正确的,`ChatPermissions` 对象不能直接用于 `setChatMemberStatus` 方法中。
以下是一个更正的 Python 代码示例,演示如何使用 `setChatMemberStatus` 方法将普通用户设置为管理员:
```python
import argparse
import sys
import json
from typing import Dict
from pyrogram import Client
from pyrogram.errors import PeerIdInvalid
from pyrogram.types import ChatPermissions, ChatMember, Message
app = Client("my_account")
async def set_admin(chat_id: int, user_id: int):
try:
chat_member = await app.get_chat_member(chat_id, user_id)
await app.set_chat_member_status(chat_id, user_id, "administrator")
print(f"User {user_id} has been promoted to admin in chat {chat_id}")
except PeerIdInvalid as e:
print(f"Failed to promote user {user_id} to admin in chat {chat_id}: {str(e)}")
async def main():
chat_id = 1234567890 # replace with the chat ID
user_id = 9876543210 # replace with the user ID
await set_admin(chat_id, user_id)
if __name__ == "__main__":
app.start()
asyncio.get_event_loop().run_until_complete(main())
app.stop()
```
在上面的代码中,我们通过 `app.get_chat_member` 方法获取了要设置为管理员的用户,然后调用 `app.set_chat_member_status` 方法将该用户的状态设置为 `administrator`。
阅读全文