Telethon: USER_ID_INVALID Error in add_chat_user

Created on 14 May 2017  路  13Comments  路  Source: LonamiWebs/Telethon

Hello again,
i wrote this code:

tg.invoke(add_chat_user.AddChatUserRequest(get_dialog_id(group),userID,0))

userID is instance of 0xd10d979a!

when i run it i have this Error
[13:32:28.303/MainThread] WARNING: Read RPC error: (RPCError(...), 'Unknown error message with code 400: USER_ID_INVALID')
tanks a lot for any help

Most helpful comment

Okay, I see the problem now. You're doing this:

userID = entity

(You should rename that, by the way, it's not an user ID, it's the whole user and it's confusing).

And then you're invoking AddChatUserRequest with it, but this request does not take an User. It takes an InputUser.

So it obviously is an invalid user ID, because you're not passing the right InputUser but rather a User. Hence, you should use get_input_peer or create the instance yourself with InputPeerUser(userID.id, userID.access_hash).

All 13 comments

userID is instance of 0xd10d979a!

There is no type whose constructor ID matches that number. The ID of an user is not instance of anything, it's just an identifier for that user. What is add_chat_user? What is group? And where did you get that userID from?

Most likely, as the error says, you got that ID wrong.

tank you for quick reply,
i'm really confused, but:
add_chat_user is AddChatUserRequest(f9a0aa09), group is result of get_more_dialogs(when isinstance(entity,Channel) and not entity.broadcast) and finaly i got userID from result of get_more_dialogs(when get_dialog_name(entity) == "SEPEC NAME")

i got userID from result of get_more_dialogs(when get_dialog_name(entity) == "SEPEC NAME")

And have you made sure that that entity isinstance(User)?

im sure, i test this code with a new account for more sure:

(user (ID: 0xd10d979a) = (is_self=None, contact=None, mutual_contact=None, deleted=None, bot=None, bot_chat_history=None, bot_nochats=None, verified=None, restricted=None, min=None, bot_inline_geo=None, id=xxxxxxxx, access_hash=7985723964210156156, first_name=xxxxxxxx, last_name=None, username=shiva_mu, phone=xxxxxxxx, photo=(userProfilePhoto (ID: 0xd559d8c8) = (photo_id=1509527876531234732, photo_small=(fileLocation (ID: 0x53d69076) = (dc_id=4, volume_id=431702678, local_id=39952, secret=943221009116748488)), photo_big=(fileLocation (ID: 0x53d69076) = (dc_id=4, volume_id=431702678, local_id=39954, secret=8549021626202464039)))), status=(userStatusOffline (ID: 0x8c703f) = (was_online=1494687059)), bot_info_version=None, restriction_reason=None, bot_inline_placeholder=None))

Are you sure you don't have to use InviteToChannelRequest since group isinstance(entity,Channel)?

Yes, im sure for example:

(channel (ID: 0xa14dca52) = (creator=None, kicked=None, left=None, editor=None, moderator=None, broadcast=None, verified=None, megagroup=True, restricted=None, democracy=None, signatures=None, min=None, id=XXXXXXXXX, access_hash=-7412826965613306161, title=XXXXXXXX, username=None, photo=(chatPhoto (ID: 0x6153276a) = (photo_small=(fileLocation (ID: 0x53d69076) = (dc_id=4, volume_id=430518807, local_id=95128, secret=5840290464406012882)), photo_big=(fileLocation (ID: 0x53d69076) = (dc_id=4, volume_id=430518807, local_id=95130, secret=-1303829869302535136)))), date=2017-04-23 15:38:49, version=0, restriction_reason=None))

But you're using AddChatUserRequest when it clearly is a channel. Don't you have to use InviteToChannelRequest for that?

totaly my code is:

dialogs, entities = tg.get_more_dialogs(int(SYSTEM['dialog_fetch']))
    while (entities):
        for i, entity in enumerate(entities):
            if(isinstance(entity,Channel)):
                if not entity.broadcast:
                    groups.append(entity)
            if(get_dialog_name(entity) == "Parazitt"):
                userID = entity
            dialogslist.append(entity)
        dialogs, entities = tg.get_more_dialogs(int(SYSTEM['dialog_fetch']))
    for entity in groups:
        tg.invoke(add_chat_user.AddChatUserRequest(get_dialog_id(entity),userID,0))

Okay, I see the problem now. You're doing this:

userID = entity

(You should rename that, by the way, it's not an user ID, it's the whole user and it's confusing).

And then you're invoking AddChatUserRequest with it, but this request does not take an User. It takes an InputUser.

So it obviously is an invalid user ID, because you're not passing the right InputUser but rather a User. Hence, you should use get_input_peer or create the instance yourself with InputPeerUser(userID.id, userID.access_hash).

problem solved i use your reply.
but sadly i have new issue :((
i have this error:

Unknown error message with code 400: CHAT_ID_INVALID')

That's being discussed on #64.

@parazitt and @Lonami how you've solved this problem? because when i am creating instance by InputPeerUser method i am getting an ERROR : Traceback (most recent call last):
File "test.py", line 46, in
fwd_limit=10 # Allow the user to see the 10 last messages
File "C:Users\abc\Desktop\tel\Telethon-master\telethon\telegram_bare_client.py", line 443, in __call__
result = self._invoke(call_receive, *requests)
File "C:Users\abc\Desktop\tel\Telethon-master\telethon\telegram_bare_client.py", line 532, in _invoke
raise next(x.rpc_error for x in requests if x.rpc_error)
telethon.errors.rpc_error_list.PeerIdInvalidError: An invalid Peer was used. Make sure to pass the right peer type

me too, I tried with this

InputPeerUser(userID.id, userID.access_hash)

but the same error. how did you fix this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ilhicas picture Ilhicas  路  3Comments

justxor picture justxor  路  4Comments

aminhyper picture aminhyper  路  3Comments

saeedesfandi picture saeedesfandi  路  3Comments

amir3code picture amir3code  路  6Comments