this is info my channel :
dialogs, entities = client.get_dialogs(1)
entity = entities[0]
print(entity)
(channel (ID: 0xa14dca52) = (creator=True, kicked=None, left=None, editor=None, moderator=None, broadcast=True, verified=None, megagroup=None, restricted=None, democracy=None, signatures=None, min=None, id=1135498252, access_hash=-6282984409346664480, title=channel_test, username=None, photo=(chatPhotoEmpty (ID: 0x37c1011c) = ()), date=2017-07-04 06:11:05, version=0, restriction_reason=None))
and i have 3 contacts :
contacts = client.invoke(GetContactsRequest(""))
for u in contacts.contacts:
print (u)
(contact (ID: 0xf911c994) = (user_id=231735496, mutual=False))
(contact (ID: 0xf911c994) = (user_id=408708469, mutual=False))
(contact (ID: 0xf911c994) = (user_id=442246143, mutual=False))
I dont know how i can use this code:
from telethon.tl.functions.messages import AddChatUserRequest
client.invoke(AddChatUserRequest(
chat_id,
user_to_add,
fwd_limit=10 # allow the user to see the 10 last messages
))
what is chat_id ? and user_to_add ?
when i use this code
client.invoke(AddChatUserRequest(
1135498252,
231735496,
fwd_limit=10 # allow the user to see the 10 last messages
))
i see this error
Traceback (most recent call last):
File "<pyshell#102>", line 4, in <module>
fwd_limit=10 # allow the user to see the 10 last messages
File "C:Python34libsite-packagestelethontelegram_client.py", line 247, in invoke
request, timeout=timeout, updates=updates)
File "C:Python34libsite-packagestelethontelegram_bare_client.py", line 188, in invoke
self.sender.send(request)
File "C:Python34libsite-packagestelethonnetworkmtproto_sender.py", line 57, in send
request.on_send(writer)
File "C:Python34libsite-packagestelethontlfunctionsmessages add_chat_user.py", line 39, in on_send
self.user_id.on_send(writer)
AttributeError: 'int' object has no attribute 'on_send'
2
Answers
As I said on the issue I presume you opened too, you need to use the
contact.users
, notcontacts.contacts
. If you want to add the first user, first retrieve it, and then use it on the request:As always, the documentation is your friend, and the documentation for
AddChatUserRequest
clearly says thatuser_id
is of typeInputUser
(but you can pass it anUser
too).Apply this way, when you add a target contract or id or username in a group…