Add new method set_bot_commands (#657) · MrBotDeveloper/pyrogram@293e852 · GitHub
Skip to content

Commit 293e852

Browse files
Add new method set_bot_commands (pyrogram#657)
* a new method set_bot_commands * Delete bot_commands_list.py * Update set_bot_commands.py * Update __init__.py * Update set_bot_commands.py * Update set_bot_commands.py * Update bot_command.py * Update set_bot_commands.py * Update set_bot_commands.py * Update compiler.py Co-authored-by: Dan <14043624+delivrance@users.noreply.github.com>
1 parent ed3576e commit 293e852

5 files changed

Lines changed: 110 additions & 2 deletions

File tree

compiler/docs/compiler.py

Lines changed: 1 addition & 0 deletions

pyrogram/methods/bots/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from .send_game import SendGame
2525
from .send_inline_bot_result import SendInlineBotResult
2626
from .set_game_score import SetGameScore
27+
from .set_bot_commands import SetBotCommands
2728

2829

2930
class Bots(
@@ -34,6 +35,7 @@ class Bots(
3435
SendInlineBotResult,
3536
SendGame,
3637
SetGameScore,
37-
GetGameHighScores
38+
GetGameHighScores,
39+
SetBotCommands
3840
):
3941
pass
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Pyrogram - Telegram MTProto API Client Library for Python
2+
# Copyright (C) 2017-2021 Dan <https://github.com/delivrance>
3+
#
4+
# This file is part of Pyrogram.
5+
#
6+
# Pyrogram is free software: you can redistribute it and/or modify
7+
# it under the terms of the GNU Lesser General Public License as published
8+
# by the Free Software Foundation, either version 3 of the License, or
9+
# (at your option) any later version.
10+
#
11+
# Pyrogram is distributed in the hope that it will be useful,
12+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
# GNU Lesser General Public License for more details.
15+
#
16+
# You should have received a copy of the GNU Lesser General Public License
17+
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
18+
19+
from typing import Optional, List
20+
21+
from pyrogram import raw
22+
from pyrogram import types
23+
from pyrogram.scaffold import Scaffold
24+
25+
26+
class SetBotCommands(Scaffold):
27+
async def set_bot_commands(self, commands: Optional[List[types.BotCommand]]):
28+
"""Set the bot commands list.
29+
30+
The commands passed will overwrite any command set previously.
31+
This method can be used by the own bot only.
32+
33+
Parameters:
34+
commands (List of :obj:`~pyrogram.types.BotCommand`):
35+
A list of bot commands.
36+
Pass None to remove all commands.
37+
38+
Returns:
39+
``bool``: True on success, False otherwise.
40+
41+
Example:
42+
.. code-block:: python
43+
44+
from pyrogram.types import BotCommand
45+
46+
# Set new commands
47+
app.set_bot_commands([
48+
BotCommand("start", "Start the bot"),
49+
BotCommand("settings", "Bot settings")])
50+
51+
# Remove commands
52+
app.set_bot_commands(None)
53+
"""
54+
55+
return await self.send(
56+
raw.functions.bots.SetBotCommands(
57+
commands=[c.write() for c in commands or []]
58+
)
59+
)

pyrogram/types/bots_and_keyboards/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from .login_url import LoginUrl
2727
from .reply_keyboard_markup import ReplyKeyboardMarkup
2828
from .reply_keyboard_remove import ReplyKeyboardRemove
29+
from .bot_command import BotCommand
2930

3031
__all__ = [
3132
"CallbackGame",
@@ -37,5 +38,6 @@
3738
"KeyboardButton",
3839
"ReplyKeyboardMarkup",
3940
"ReplyKeyboardRemove",
40-
"LoginUrl"
41+
"LoginUrl",
42+
"BotCommand",
4143
]
Lines changed: 44 additions & 0 deletions

0 commit comments

Comments
 (0)