1

我正在使用该库在 python 中开发一个小机器人,python-telegram-bot但遇到了一个小问题:

我有一个InlineKeyboardButton带有参数的switch_inline_query_current_chat,所以当用户点击它时,一个命令会自动写入它的聊天中。

但是,该命令之前提到了机器人(带有@)。

问题是我的机器人在这种情况下没有回答,我不知道为什么..

有没有一种解决方案可以使按钮不在命令之前提到机器人?

来自@BotFather组被允许并且隐私组被关闭。

十分感谢

编辑:这是 CommandHandler 的代码:

def getEntry(update, context):
if not (is_allowed_user(update.message.from_user.username, 'getEntry')):
    context.bot.send_message(chat_id=update.effective_chat.id,
                             text='Who the hell are you @' + update.message.from_user.username + ' ?')
    return
search = ' '.join(context.args)

infos, err = get_infos_people(search)

if err is not None:
    context.bot.send_message(chat_id=update.effective_chat.id, text=err)
    return

context.bot.send_message(chat_id=update.effective_chat.id, text=beautify_infos(infos),
                         parse_mode=ParseMode.MARKDOWN, reply_markup=getMainKeyboard(infos))
get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)

这是按钮的代码:

def getMainKeyboard(infos):
keyboard = [InlineKeyboardButton("modify",
                                  switch_inline_query_current_chat="/get " + infos[0] + "<write here>")]]
return InlineKeyboardMarkup(keyboard)
4

1 回答 1

0

注意:我不是 python-telegram-bot 专家,但问题/修复应该与 lib 无关


commandHandler()的定义是这样的:

get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)

这会将/get命令链接到getEntry处理程序。


问题

由于该命令在 触发/get,因此您需要添加第二个带有机器人名称的命令,以便它也会注册该命令;

get_handler = CommandHandler([ 'get', 'get@myBot' ], getEntry, filters=~Filters.update.edited_message)

文档所示,第一个参数 ( command) 同时接受 astr或 alist


在其他一些图书馆也有同样的问题,不要认为有一种“更干净”的方式来处理这个问题。

于 2020-06-10T16:33:46.290 回答