提及时电报机器人没有响应

2024-05-19 00:21:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在用python开发一个带有库python-telegram-bot的小机器人,我遇到了一个小问题:

我有一个带有参数switch_inline_query_current_chatInlineKeyboardButton,因此当用户单击它时,一个命令会自动写入其聊天记录中

但是,该命令前面提到了bot(带有@)

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

有没有一个解决方案,使按钮不在命令前面提到机器人

@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)

Tags: text命令sendidmessagegetbotcontext
1条回答
网友
1楼 · 发布于 2024-05-19 00:21:21

注意:我不是python telegram机器人专家,但问题/修复应该与库无关


您的^{}定义如下:
get_handler = CommandHandler('get', getEntry, filters=~Filters.update.edited_message)

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


问题

由于该命令仅在/get触发,因此需要添加第二个具有bot名称的命令,以便它也将注册该命令

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

第一个参数(command)接受strlist作为docs shows


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

相关问题 更多 >

    热门问题