【问题标题】:Telegram bot not responding when mentionned提到电报机器人时没有响应
【发布时间】:2020-09-26 07:08:05
【问题描述】:

我正在使用库 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 bots telegram telegram-bot python-telegram-bot


【解决方案1】:

注意:我不是 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) 接受 strlist 作为 docs shows


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

【讨论】:

  • 嗨!谢谢你的回答,我的迟到了,因为很多工作。无论如何,不​​幸的是,这不起作用。 Command is not a valid bot command 因为 @ 我想。我将尝试捕获每条消息,并自行过滤,无需图书馆的帮助。
  • 嗨,谢谢,我猜你必须向库提交错误报告,因为这应该可以工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-05-13
  • 2017-08-18
  • 1970-01-01
  • 2021-09-06
  • 2021-05-25
  • 2021-08-18
  • 2020-08-09
相关资源
最近更新 更多