0

This code:

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)

Returns:

AttributeError: 'InputPeerChannel' object has no attribute 'to_bytes'

In docs:

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.

What`s wrong? Maybe my udata in the wrong type?

1 Answers1

0

I'm not sure, but "DeleteChatUser" it seems to only work for groups, not channels.

For groups maybe working code:

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)

But I needed a solution for the channel, so I used:

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