1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Merge pull request #1418 from artyl/master

add default None for get_my_commands, examples for bot.set_my_commands
This commit is contained in:
Badiboy 2022-01-21 22:48:11 +03:00 committed by GitHub
commit cf2eb1fec7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 70 additions and 7 deletions

View File

@ -0,0 +1,35 @@
#!/usr/bin/python
# This is a set_my_commands example.
# Press on [/] button in telegram client.
# Important, to update the command menu, be sure to exit the chat with the bot and log in again
# Important, command for chat_id and for group have a higher priority than for all
import asyncio
import telebot
from telebot.async_telebot import AsyncTeleBot
API_TOKEN = '<api_token>'
bot = AsyncTeleBot(API_TOKEN)
async def main():
# use in for delete with the necessary scope and language_code if necessary
await bot.delete_my_commands(scope=None, language_code=None)
await bot.set_my_commands(
commands=[
telebot.types.BotCommand("command1", "command1 description"),
telebot.types.BotCommand("command2", "command2 description")
],
# scope=telebot.types.BotCommandScopeChat(12345678) # use for personal command menu for users
# scope=telebot.types.BotCommandScopeAllPrivateChats() # use for all private chats
)
cmd = await bot.get_my_commands(scope=None, language_code=None)
print([c.to_json() for c in cmd])
if __name__ == '__main__':
asyncio.run(main())

View File

@ -5,7 +5,7 @@
# https://schedule.readthedocs.io # https://schedule.readthedocs.io
import asyncio import asyncio
import os, aioschedule import aioschedule
from telebot.async_telebot import AsyncTeleBot from telebot.async_telebot import AsyncTeleBot
API_TOKEN = '<api_token>' API_TOKEN = '<api_token>'

View File

@ -0,0 +1,28 @@
#!/usr/bin/python
# This is a set_my_commands example.
# Press on [/] button in telegram client.
# Important, to update the command menu, be sure to exit the chat with the bot and enter to chat again
# Important, command for chat_id and for group have a higher priority than for all
import telebot
API_TOKEN = '<api_token>'
bot = telebot.TeleBot(API_TOKEN)
# use in for delete with the necessary scope and language_code if necessary
bot.delete_my_commands(scope=None, language_code=None)
bot.set_my_commands(
commands=[
telebot.types.BotCommand("command1", "command1 description"),
telebot.types.BotCommand("command2", "command2 description")
],
# scope=telebot.types.BotCommandScopeChat(12345678) # use for personal command for users
# scope=telebot.types.BotCommandScopeAllPrivateChats() # use for all private chats
)
# check command
cmd = bot.get_my_commands(scope=None, language_code=None)
print([c.to_json() for c in cmd])

View File

@ -3,7 +3,7 @@
# This is a simple bot with schedule timer # This is a simple bot with schedule timer
# https://schedule.readthedocs.io # https://schedule.readthedocs.io
import os, time, threading, schedule import time, threading, schedule
from telebot import TeleBot from telebot import TeleBot
API_TOKEN = '<api_token>' API_TOKEN = '<api_token>'

View File

@ -1899,8 +1899,8 @@ class TeleBot:
""" """
return apihelper.delete_chat_photo(self.token, chat_id) return apihelper.delete_chat_photo(self.token, chat_id)
def get_my_commands(self, scope: Optional[types.BotCommandScope], def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
language_code: Optional[str]) -> List[types.BotCommand]: language_code: Optional[str]=None) -> List[types.BotCommand]:
""" """
Use this method to get the current list of the bot's commands. Use this method to get the current list of the bot's commands.
Returns List of BotCommand on success. Returns List of BotCommand on success.
@ -3415,4 +3415,4 @@ class TeleBot:

View File

@ -2443,8 +2443,8 @@ class AsyncTeleBot:
""" """
return await asyncio_helper.delete_chat_photo(self.token, chat_id) return await asyncio_helper.delete_chat_photo(self.token, chat_id)
async def get_my_commands(self, scope: Optional[types.BotCommandScope], async def get_my_commands(self, scope: Optional[types.BotCommandScope]=None,
language_code: Optional[str]) -> List[types.BotCommand]: language_code: Optional[str]=None) -> List[types.BotCommand]:
""" """
Use this method to get the current list of the bot's commands. Use this method to get the current list of the bot's commands.
Returns List of BotCommand on success. Returns List of BotCommand on success.