我创建了一个机器人(使用python-telegram-bot),在选择一种查询类型时,机器人应该随机选择一个可用字符串作为回复。
我创建回复的功能如下:
def generate_reply():
replies = """
Hello
Goodbye
Thanks!
Your welcome!
See you around!""".splitlines()
r = random.choice(replies).strip()
return r
回复用户的功能如下:
#Inline Reply
def inlinequery(update, context):
query = update.inline_query.query
results = [InlineQueryResultArticle(id=uuid4(), title="Interact",
input_message_content=InputTextMessageContent(
generate_reply()))]
update.inline_query.answer(results)
#Normal reply
def reply(update, context):
update.message.reply_text(generate_reply())
创建机器人后,我使用以下命令将其添加到机器人中:
dp.add_handler(CommandHandler("reply", reply))
dp.add_handler(InlineQueryHandler(inlinequery))
当我/reply在聊天中使用它时,它按预期工作,但是无论我在与另一个用户或组聊天时使用内联命令,随机选择显然停止工作。我怎样才能解决这个问题?