是否可以用斜杠制作文本消息=命令? Telegram python 机器人

Is it possible to make text message = command with slash? Telegram python bot

我创建了电报机器人,现在它通过带斜线的 commandhandler 使用命令来激活不同的功能,但问题是 - 是否有可能让他理解 text = /command,例如(“是,Y,是, 是" = /是).

我想保留我的 commandhandlers,但想用没有斜杠的命令制作键盘按钮。

self._keyboard: List[List[Union[str, KeyboardButton]]] = [
                                   ['/yes', '/no', '/sure'],
                                   ['/absolutely', '/allright'],


handles = [
CommandHandler('yes', self._yes),
CommandHandler('no', self._no),
CommandHandler('sure', self._sure),
CommandHandler('absolutely', self._absolutely),
CommandHandler('allright', self._allright),

#New added string: (Big Thanks to the user CallMeStag)
MessageHandler(Filters.regex('^yes$'), self._yes),
]



#I can start bot, bot not every function working, under is error which i got:
AttributeError: MessageHandler object has no attribute command

KeyboardButtons 只是使用它们显示的文本发送消息的快捷方式。你不能让他们发送不同的文本。 您可以 做的是简单地处理非命令消息。如果您收到一条包含文本 yes/Y/Yes/YES 的消息,只需 运行 与您 运行 相同的代码/yes.

编辑:使用python-telegram-bot,您可以使用MessageHandler and e.g. Filters.regex:

MessageHandler(Filters.regex('^yes|Y|Yes|YES$'), self._yes)