Skip to content

Instantly share code, notes, and snippets.

@sh4dowb
Last active December 9, 2021 09:02
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sh4dowb/861934f2d0472400c6f9a764b4b7589d to your computer and use it in GitHub Desktop.
telethon get if participant is admin
from telethon.tl.types import ChannelParticipantCreator, ChannelParticipantAdmin
from telethon.tl.functions.channels import GetParticipantRequest
#..
@client.on(events.NewMessage)
async def handler(event):
participant = await client(GetParticipantRequest(channel=event.original_update.message.to_id.channel_id,user_id=event.original_update.message.from_id))
isadmin = (type(participant.participant) == ChannelParticipantAdmin)
iscreator = (type(participant.participant) == ChannelParticipantCreator)
print(isadmin, iscreator)
@jmcambot
Copy link

jmcambot commented Dec 9, 2021

Hi, thank you very much for this code that works! It was very useful to me to detect the reliability of a user when a post is published in a group, and a bot is reading it.
There is just a mistake, probably changed since the version of your post, you need to replace user_id=... with participant=...
And of course it may be necessary to manage errors when data is not as clean as we expected :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment