【问题标题】:Command with arguments in pyTelegramBotAPIpyTelegramBotAPI 中带参数的命令
【发布时间】:2017-11-22 01:22:30
【问题描述】:

pyTelegramBotAPI 版本 - 3.0.1

python 版本: 2.7/3.6.1

我想创建一个带参数的命令,例如:

/activate 1
/run programm

怎么做?

【问题讨论】:

  • @NoamHacker,我想过分割结果线,但我不知道如何正确地做到这一点。

标签: python arguments telegram py-telegram-bot-api


【解决方案1】:

解决方案:

def extract_arg(arg):
    return arg.split()[1:]

@bot.message_handler(commands=['yourCommand'])
def yourCommand(message):
    status = extract_arg(message.text)

/yourCommand 1

status = ['1']

/yourCommand ff

status = ['ff']

【讨论】:

    猜你喜欢
    • 2013-06-04
    • 2012-02-25
    • 2019-10-09
    • 2021-01-26
    • 2020-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    相关资源
    最近更新 更多