From d6161515c142b62107e374dcbe358a9b9c52b195 Mon Sep 17 00:00:00 2001 From: Profitroll <47523801+profitrollgame@users.noreply.github.com> Date: Sat, 10 Dec 2022 15:51:48 +0100 Subject: [PATCH] Improved registration logic --- modules/commands_register.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/modules/commands_register.py b/modules/commands_register.py index 44b87a5..20a1419 100644 --- a/modules/commands_register.py +++ b/modules/commands_register.py @@ -1,3 +1,4 @@ +from modules.logging import logWrite from modules.utils import configGet from pyrogram.types import BotCommand, BotCommandScopeChat from pyrogram.errors import bad_request_400 @@ -24,16 +25,25 @@ def commands_register(app): except bad_request_400.PeerIdInvalid: pass - app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("owner"))) + try: + app.set_bot_commands(commands_admin_list, scope=BotCommandScopeChat(chat_id=configGet("owner"))) + except bad_request_400.PeerIdInvalid: + logWrite(f"Could not register commands for bot owner. Perhaps user has not started the bot yet.") # Registering admin group commands commands_group_admin_list = [] for command in configGet("commands_group_admin"): commands_group_admin_list.append(BotCommand(command, configGet("commands_group_admin")[command])) - app.set_bot_commands(commands_group_admin_list, scope=BotCommandScopeChat(chat_id=configGet("admin_group"))) + try: + app.set_bot_commands(commands_group_admin_list, scope=BotCommandScopeChat(chat_id=configGet("admin_group"))) + except bad_request_400.ChannelInvalid: + logWrite(f"Could not register commands for admin group. Bot is likely not in the group.") # Registering destination group commands commands_group_destination_list = [] for command in configGet("commands_group_destination"): commands_group_destination_list.append(BotCommand(command, configGet("commands_group_destination")[command])) - app.set_bot_commands(commands_group_destination_list, scope=BotCommandScopeChat(chat_id=configGet("destination_group"))) \ No newline at end of file + try: + app.set_bot_commands(commands_group_destination_list, scope=BotCommandScopeChat(chat_id=configGet("destination_group"))) + except bad_request_400.ChannelInvalid: + logWrite(f"Could not register commands for destination group. Bot is likely not in the group.") \ No newline at end of file