Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ChatAdminRequired error by sending warning messages #282

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/korone/filters/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

from hydrogram import Client
from hydrogram.enums import ChatMemberStatus, ChatType
from hydrogram.errors import ChatAdminRequired
from hydrogram.filters import Filter
from hydrogram.types import CallbackQuery, ChatPrivileges, Message

Expand Down Expand Up @@ -34,9 +35,18 @@ async def __call__(self) -> bool:
if message.chat.type == ChatType.PRIVATE:
return True

chat_member = await message.chat.get_member(user.id)
if chat_member.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
return True
try:
chat_member = await message.chat.get_member(user.id)
if chat_member.status in {ChatMemberStatus.ADMINISTRATOR, ChatMemberStatus.OWNER}:
return True
except ChatAdminRequired:
if self.show_alert:
alert_text = _("I need to be an administrator to perform that action!")
if is_callback:
await update.answer(text=alert_text, show_alert=True, cache_time=60)
else:
await message.reply(alert_text)
return False

if self.show_alert:
alert_text = _("You must be an administrator to use this.")
Expand Down
Loading