Closed the-lookin closed 7 years ago
Well, it seems like you need to be an admin:
ChatAdminRequiredError
Don't use ChannelParticipantsRecent
. Use something else. And please format the code more nicely next time, it's not so hard to do it:
```python
code here
```
Something like what?
No idea, test or use search. I know how the API works, not how to work with the API.
I'am also having the same issue. GetParticipantsRequest returns:
ChatAdminRequiredError(...), Chat admin privileges are required to do that in the specified chat (for e
xample, to send a message in a channel which is not yours)
when I try to get the usernames inside my own telegram channel, in which I'am Admin. The interesting part is that the same routine works for groups of mine. Only channels are not working.
Here goes the routine:
def getUserNames(channel):
offset = 0
limit = 100
all_participants = []
selected_participants = []
channel = client(ResolveUsernameRequest(channel))
while True:
participants = client.invoke(GetParticipantsRequest(
InputChannel(channel.chats[0].id, channel.chats[0].access_hash), ChannelParticipantsSearch(''), offset, limit, 0)
)
if not participants.users:
break
all_participants.extend(participants.users)
offset += len(participants.users)
if len(all_participants):
for x in all_participants:
if x.username: selected_participants.append(x.username)
return selected_participants
else:
return -1
Is there something I'am missing here?
InputChannel(channel.chats[0].id, channel.chats[0].access_hash)
That's redundant, the library will do it for you. Besides that I've no idea, it should work, make sure you're using the right channel and all that.
from telethon import TelegramClient, sync
api_id = 00000
api_hash = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
client = TelegramClient('xxx', api_id, api_hash).start()
for u in client.get_participants('ChannelUserName'):
print(u.id, u.first_name, u.last_name, u.username)
Work 100%
@l33t-daniel certainly doesn't work now)
Sorry for resurrecting the old issue but
Is there a way to check if logged in user has enough rights to call GetParticipantsRequest
for a given chat / channel? I don't feel comfortable to try/except for ChatAdminRequiredError
each time. Maybe I can somehow check that with chat/channel metadata?
I've tried to analyse the chat info to understand which field tells me that I can iterate over chat's participants. But I couldn't find it. Here is an example of a chat which allows me to iterate over its participants:
{'_': 'Channel',
'id': *******,
'title': '******',
'photo': {'_': 'ChatPhoto',
'photo_id': *******,
'dc_id': 2,
'has_video': False,
'stripped_thumb': b'\x01\x08\x08\xa9\x1c\xab\x18Ud\xe4w\x1dh\xa2\x8a,6\xcf'},
'date': datetime.datetime(2023, 9, 18, 14, 12, 1, tzinfo=datetime.timezone.utc),
'creator': False,
'left': True,
'broadcast': False,
'verified': False,
'megagroup': True,
'restricted': False,
'signatures': False,
'min': False,
'scam': False,
'has_link': True,
'has_geo': False,
'slowmode_enabled': False,
'call_active': False,
'call_not_empty': False,
'fake': False,
'gigagroup': False,
'noforwards': False,
'join_to_send': False,
'join_request': False,
'forum': False,
'access_hash': *********,
'username': '********',
'restriction_reason': [],
'admin_rights': None,
'banned_rights': None,
'default_banned_rights': {'_': 'ChatBannedRights',
'until_date': datetime.datetime(2038, 1, 19, 3, 14, 7, tzinfo=datetime.timezone.utc),
'view_messages': False,
'send_messages': False,
'send_media': False,
'send_stickers': False,
'send_gifs': False,
'send_games': False,
'send_inline': False,
'embed_links': False,
'send_polls': False,
'change_info': True,
'invite_users': False,
'pin_messages': True,
'manage_topics': False,
'send_photos': False,
'send_videos': False,
'send_roundvideos': False,
'send_audios': False,
'send_voices': False,
'send_docs': False,
'send_plain': False},
'participants_count': 3,
'usernames': []}
I believe we are allowed to view the participants of megagroup channels, but I haven't been able to find any official information confirming this.
@AveZorgen, dont think so, because I openned Telegram App and join any channel, but can not see other user of this channel. It's seem only admin can see
I have a problem with getting all members of chanel. It`s an error 400:
This is code: