#289 added setMyCommands method; added BotCommand type

This commit is contained in:
Oleg A 2020-04-05 16:35:56 +03:00
parent 0f245bbf56
commit b77ed1ad92
4 changed files with 32 additions and 0 deletions

View file

@ -206,6 +206,7 @@ class Methods(Helper):
SET_CHAT_STICKER_SET = Item() # setChatStickerSet
DELETE_CHAT_STICKER_SET = Item() # deleteChatStickerSet
ANSWER_CALLBACK_QUERY = Item() # answerCallbackQuery
SET_MY_COMMANDS = Item() # setMyCommands
# Updating messages
EDIT_MESSAGE_TEXT = Item() # editMessageText

View file

@ -1520,6 +1520,24 @@ class Bot(BaseBot, DataMixin, ContextInstanceMixin):
result = await self.request(api.Methods.ANSWER_CALLBACK_QUERY, payload)
return result
async def set_my_commands(self, commands: typing.List[types.BotCommand]) -> base.Boolean:
"""
Use this method to change the list of the bot's commands.
Source: https://core.telegram.org/bots/api#setmycommands
:param commands: A JSON-serialized list of bot commands to be set as the list of the bot's commands.
At most 100 commands can be specified.
:type commands: :obj: `typing.List[types.BotCommand]`
:return: Returns True on success.
:rtype: base.Boolean
"""
commands = prepare_arg(commands)
payload = generate_payload(**locals())
result = await self.request(api.Methods.SET_MY_COMMANDS, payload)
return result
async def edit_message_text(self, text: base.String,
chat_id: typing.Union[base.Integer, base.String, None] = None,
message_id: typing.Union[base.Integer, None] = None,

View file

@ -3,6 +3,7 @@ from . import fields
from .animation import Animation
from .audio import Audio
from .auth_widget_data import AuthWidgetData
from .bot_command import BotCommand
from .callback_game import CallbackGame
from .callback_query import CallbackQuery
from .chat import Chat, ChatActions, ChatType

View file

@ -0,0 +1,12 @@
from . import base
from . import fields
class BotCommand(base.TelegramObject):
"""
This object represents a bot command.
https://core.telegram.org/bots/api#botcommand
"""
command: base.String = fields.Field()
description: base.String = fields.Field()