Answer the question
In order to leave comments, you need to log in
How can I find out if the admin sent a message or not?
Hey!
How to find out the user with what role sent a message to the chat?
I have a bot in the chat, but in the incoming event there is no sign of an admin or not.
I tried this, it's strange, it works, then it gives an error:
@bot.on(events.NewMessage())
async def delurls(event):
if findurl(event.message.text):
participant = await bot(GetParticipantRequest(channel=event.original_update.message.to_id.channel_id,participant=event.original_update.message.from_id))
isadmin = (type(participant.participant) == ChannelParticipantAdmin)
iscreator = (type(participant.participant) == ChannelParticipantCreator)
if isadmin or iscreator:
pass
else:
await bot.delete_messages(event.chat, event.message)
2021-07-20 02:06:57,649 [ERROR] telethon.client.updates - _dispatch_update:470 - Unhandled exception on delurls
Traceback (most recent call last):
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/client/updates.py", line 454, in _dispatch_update
await callback(event)
File "/home/bot/fnkbot/FNKBot.py", line 43, in delurls
participant = await bot(GetParticipantRequest(channel=event.original_update.message.to_id.channel_id,participant=event.original_update.message.from_id))
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/client/users.py", line 30, in __call__
return await self._call(self._sender, request, ordered=ordered)
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/client/users.py", line 37, in _call
await r.resolve(self, utils)
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/tl/functions/channels.py", line 865, in resolve
self.participant = utils.get_input_peer(await client.get_input_entity(self.participant))
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/client/users.py", line 438, in get_input_entity
peer = utils.get_peer(peer)
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/utils.py", line 993, in get_peer
_raise_cast_fail(peer, 'Peer')
File "/home/bot/fnkbot/lib/python3.7/site-packages/telethon/utils.py", line 139, in _raise_cast_fail
type(entity).__name__, target))
TypeError: Cannot cast NoneType to any kind of Peer.
Answer the question
In order to leave comments, you need to log in
As an alternative solution, I can suggest making an entry in the config / db / pr. id of certain roles and then, when processing the command, compare the sender's id with the saved id.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question