Skip to content

Commit a07bf86

Browse files
committed
add default None for get_my_commands parameters scope and language_code sync\async, add examples for bot.set_my_commands
1 parent 64c4aca commit a07bf86

4 files changed

Lines changed: 70 additions & 5 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python
2+
3+
# This is a set_my_commands example.
4+
# Press on [/] button in telegram client.
5+
# Important, to update the command menu, be sure to exit the chat with the bot and log in again
6+
# Important, command for chat_id and for group have a higher priority than for all
7+
8+
import asyncio
9+
import os
10+
import telebot
11+
from telebot.async_telebot import AsyncTeleBot
12+
13+
14+
API_TOKEN = '<api_token>'
15+
bot = AsyncTeleBot(API_TOKEN)
16+
17+
18+
async def main():
19+
# use in for delete with the necessary scope and language_code if necessary
20+
await bot.delete_my_commands(scope=None, language_code=None)
21+
22+
await bot.set_my_commands(
23+
commands=[
24+
telebot.types.BotCommand("command1", "command1 description"),
25+
telebot.types.BotCommand("command2", "command2 description")
26+
],
27+
# scope=telebot.types.BotCommandScopeChat(12345678) # use for personal command menu for users
28+
# scope=telebot.types.BotCommandScopeAllPrivateChats() # use for all private chats
29+
)
30+
31+
cmd = await bot.get_my_commands(scope=None, language_code=None)
32+
print([c.to_json() for c in cmd])
33+
34+
35+
if __name__ == '__main__':
36+
asyncio.run(main())

‎examples/set_command_example.py‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/python
2+
3+
# This is a set_my_commands example.
4+
# Press on [/] button in telegram client.
5+
# Important, to update the command menu, be sure to exit the chat with the bot and enter to chat again
6+
# Important, command for chat_id and for group have a higher priority than for all
7+
8+
import os
9+
import telebot
10+
11+
12+
API_TOKEN = '<api_token>'
13+
bot = telebot.TeleBot(API_TOKEN)
14+
15+
# use in for delete with the necessary scope and language_code if necessary
16+
bot.delete_my_commands(scope=None, language_code=None)
17+
18+
bot.set_my_commands(
19+
commands=[
20+
telebot.types.BotCommand("command1", "command1 description"),
21+
telebot.types.BotCommand("command2", "command2 description")
22+
],
23+
# scope=telebot.types.BotCommandScopeChat(12345678) # use for personal command for users
24+
# scope=telebot.types.BotCommandScopeAllPrivateChats() # use for all private chats
25+
)
26+
27+
# check command
28+
cmd = bot.get_my_commands(scope=None, language_code=None)
29+
print([c.to_json() for c in cmd])

‎telebot/__init__.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,8 +1899,8 @@ def delete_chat_photo(self, chat_id: Union[int, str]) -> bool:
18991899
"""
19001900
return apihelper.delete_chat_photo(self.token, chat_id)
19011901

1902-
def get_my_commands(self, scope: Optional[types.BotCommandScope],
1903-
language_code: Optional[str]) -> List[types.BotCommand]:
1902+
def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
1903+
language_code: Optional[str]=None) -> List[types.BotCommand]:
19041904
"""
19051905
Use this method to get the current list of the bot's commands.
19061906
Returns List of BotCommand on success.
@@ -3415,4 +3415,4 @@ def _notify_command_handlers(self, handlers, new_messages):
34153415

34163416

34173417

3418-
3418+

‎telebot/async_telebot.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2443,8 +2443,8 @@ async def delete_chat_photo(self, chat_id: Union[int, str]) -> bool:
24432443
"""
24442444
return await asyncio_helper.delete_chat_photo(self.token, chat_id)
24452445

2446-
async def get_my_commands(self, scope: Optional[types.BotCommandScope],
2447-
language_code: Optional[str]) -> List[types.BotCommand]:
2446+
async def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
2447+
language_code: Optional[str]=None) -> List[types.BotCommand]:
24482448
"""
24492449
Use this method to get the current list of the bot's commands.
24502450
Returns List of BotCommand on success.

0 commit comments

Comments
 (0)