[我正在使用python-telegram-bot
库在python中开发一个小机器人,但我遇到了一个小问题:
我有一个带有参数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)
注意:我不是python-telegram-bot专家,但是问题/修复程序应该与lib无关
commandHandler()
定义如下:commandHandler()
这会将get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)
命令链接到/get
处理程序。
由于该命令是在getEntry
处触发的,所以您需要添加第二个命令,该命令的名称是bot的名称,以便它也可以注册该命令;/get
在其他一些库中也有同样的问题,不要认为有“更清洁”的方式来处理这个问题。第一个参数(
get_handler = CommandHandler([ 'get', 'get@myBot' ], getEntry, filters=~Filters.update.edited_message)
)接受command
或str
作为list