任何字符串的通配符 - Telegram-Bot

问题描述 投票:0回答:1

好吧,我正在使用电报机器人更新程序来处理发送给它的消息。但是,我希望它能够响应我给出的任何字符串,之前使用“#”。

尝试过AnyString方法,但没有用。另外,尝试了“*”wilcard的事情。

from telegram.ext import Updater, CommandHandler

def hello(bot, update):
    update.message.reply_text(
        'Hey {}!'.format(update.message.from_user.first_name))


updater = Updater('770165564:AAEJm45dqDNkOnlso0YK6hQoCbXoCySiHcQ')

updater.dispatcher.add_handler(CommandHandler('*', hello))

updater.start_polling()
updater.idle()

当我发送一些消息,如“/ anything”,“/ test”时,机器人将回复我描述的功能,说“嘿{user-name}!”。

python python-telegram-bot
1个回答
1
投票

你可以使用前缀处理程序(qazxsw poi)

例子:

单个前缀和命令:

docs

多个前缀,单个命令:

PrefixHandler('!', 'test', callback) will respond to '!test'.

多个前缀和命令:

PrefixHandler(['!', '#'], 'test', callback) will respond to '!test' and
'#test'.
© www.soinside.com 2019 - 2024. All rights reserved.