Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
电报Python Bot,它使用命令中的参数解释某些首字母缩略词_Python_Telegram_Telegram Bot_Python Telegram Bot - Fatal编程技术网

电报Python Bot,它使用命令中的参数解释某些首字母缩略词

电报Python Bot,它使用命令中的参数解释某些首字母缩略词,python,telegram,telegram-bot,python-telegram-bot,Python,Telegram,Telegram Bot,Python Telegram Bot,我想创建一个解释某些首字母缩略词的电报机器人。我想在群聊中使用它,这就是为什么我想使用它,比如:/首字母缩略词blabla。我能够使用通过命令传递的参数。我想像这样对给定的论点进行解释 def acronym(update, context): command = "".join(context.args) acronyms = [ "text one", "text two" ] if command == "

我想创建一个解释某些首字母缩略词的电报机器人。我想在群聊中使用它,这就是为什么我想使用它,比如:/首字母缩略词blabla。我能够使用通过命令传递的参数。我想像这样对给定的论点进行解释

def acronym(update, context):
command = "".join(context.args)
acronyms = [
    "text one",
    "text two"
]
if command == "2B":
    answer = acronyms[0]
else:
    answer = acronyms[1]
update.message.reply_text(answer, parse_mode=ParseMode.MARKDOWN_V2)

我怎样才能通过论证和比较得到正确的解释?由于该命令应在类似于/首字母缩写词2B的组中使用,因此使用类似于InlineKeyboardButton的菜单没有意义。我觉得CallbackQueryHandler可能会有帮助,但如果没有菜单,我就无法思考如何使用它。

创建一个字典来存储首字母缩写词和解释

  myDictionary = { "acro1": "expl1", "acro2": "expl2"}
每次机器人接收到命令时,搜索相应的密钥:

for key in myDictionary:
    if key == command:
        answer=myDictionary[key]

似乎动态插入答案会导致某种错误<代码>文件“C:\Users \-\AppData\Local\Programs\Python\Python38-32\lib\site packages\telegram\utils\request.py”,第330行,在post result=self.\u request\u wrapper('post',url,文件“C:\Users \-\AppData\Local\Programs\Python\Python38-32\lib\site packages\telegrames\utils\request.py”,第244行,在\u request\u request(message)中Telegrame.error.BadRequest:无法分析实体:保留字符“.”,必须使用前面的“\”进行转义好的,我通过删除parse mode选项消除了错误