python-3.x 热解图原始方法DeleteChatUser不工作

tquggr8v  于 2023-01-14  发布在  Python
关注(0)|答案(1)|浏览(87)

此代码:

usr = await app.resolve_peer(uid)
udata = InputUser(user_id=usr.user_id, access_hash=usr.access_hash)
r = await app.invoke(functions.messages.DeleteChatUser(chat_id=chan, user_id=udata))
print(r)

退货:
AttributeError: 'InputPeerChannel' object has no attribute 'to_bytes'
文档中:

class pyrogram.raw.functions.messages.DeleteChatUser**

Deletes a user from a chat and sends a service message on it.

Parameters:
chat_id (int 64-bit) – Chat ID.
user_id (InputUser) – User ID to be deleted.
revoke_history (bool, optional) – Remove the entire chat history of the specified user in this chat.

出什么问题了?也许我的udata类型不对?

kcugc4gi

kcugc4gi1#

我不确定,但“DeleteChatUser”似乎只适用于组,而不是频道。
对于团体,可能是工作代码:

cid = -10083757838484 # Example group_id
usr = await app.resolve_peer(uid)
if cid < 0:
    cid = cid * (-1) # Removing a minus from group_id
udata = InputUser(user_id=usr.user_id, access_hash=usr.access_hash)
r = await app.invoke(functions.messages.DeleteChatUser(chat_id=cid, user_id=udata))
print(r)

但我需要一个通道解决方案,所以我使用了:

r = await app.ban_chat_member(int(cid), int(usr))

相关问题