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 Answer 1

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)
cid = abs(cid)
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))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.