File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -39,6 +39,21 @@ async def log_update(update, context):
3939 logger .info (log_message )
4040
4141
42+ async def post_init (application : Application ):
43+ """Set the bot commands on startup."""
44+ from telegram import BotCommand
45+ commands = []
46+ for command_name , command_info in COMMANDS .items ():
47+ if 'description' in command_info and command_info ['description' ]:
48+ # Telegram commands must be lowercase and 1-32 chars
49+ commands .append (BotCommand (command_name .lower (), command_info ['description' ][:256 ]))
50+
51+ try :
52+ await application .bot .set_my_commands (commands )
53+ logging .getLogger ("DCUBABOT" ).info ("Successfully set bot commands." )
54+ except Exception as e :
55+ logging .getLogger ("DCUBABOT" ).error (f"Failed to set bot commands: { e } " )
56+
4257def main ():
4358 """Start the bot."""
4459 logging .basicConfig (
@@ -47,7 +62,7 @@ def main():
4762 )
4863
4964
50- application = Application .builder ().token (os .environ ["TELEGRAM_BOT_TOKEN" ]).build ()
65+ application = Application .builder ().token (os .environ ["TELEGRAM_BOT_TOKEN" ]).post_init ( post_init ). build ()
5166
5267 application .add_error_handler (error_handler )
5368
You can’t perform that action at this time.
0 commit comments