Привет!
Как узнать пользователь с какой ролью отправил сообщение в чат?
У меня есть бот в чате, но во входящем ивенте нет признака админ или нет.
Пробовал так, то странно, то работает, то ошибку выдает:
@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.