Python 我的电报机器人在个人聊天中应答,但don';小组聊天。为什么?
我的电报机器人在个人聊天中应答,但不在集体聊天中应答。我找不到问题。 我的代码片段:Python 我的电报机器人在个人聊天中应答,但don';小组聊天。为什么?,python,telegram,python-telegram-bot,telegram-webhook,Python,Telegram,Python Telegram Bot,Telegram Webhook,我的电报机器人在个人聊天中应答,但不在集体聊天中应答。我找不到问题。 我的代码片段: @app.route('/{}'.format(TOKEN), methods=['POST']) def respond(): # retrieve the message in JSON and then transform it to Telegram object update = telegram.Update.de_json(request.get_json(force=True),
@app.route('/{}'.format(TOKEN), methods=['POST'])
def respond():
# retrieve the message in JSON and then transform it to Telegram object
update = telegram.Update.de_json(request.get_json(force=True), bot)
# get the chat_id to be able to respond to the same user
chat_id = update.message.chat.id
# Telegram understands UTF-8, so encode text for unicode compatibility
text = update.message.text
if text == '/start':
response = send_welcome()
bot.sendMessage(chat_id=chat_id, text=response)
elif 'discord' in text.split():
response = send_discord()
bot.sendMessage(chat_id=chat_id, text=response)
elif 'edeka' in text.split():
response = send_edeka()
bot.sendMessage(chat_id=chat_id, text=response)
elif 'random' in text.split():
response = send_random()
bot.sendMessage(chat_id=chat_id, text=response)
elif 'metro' in text.split():
response = send_metro()
bot.sendMessage(chat_id=chat_id, text=response)
elif text == '/help':
response = send_help()
bot.sendMessage(chat_id=chat_id, text=response)
elif text == 'Good bot':
response = 'Önemli degil kanka'
bot.sendMessage(chat_id=chat_id, text=response)
return 'ok'
我在heroku中收到text.split()的错误消息,但仅来自群聊。#获取聊天id以便能够响应同一用户
chat\u id=update.message.chat.id
这是来自发送消息的人。因此,如果一个人在群聊中以你的机器人为目标,你将回复他的个人id
考虑使用
chat\u id=update.message.from.id
这是发送消息的聊天室,在这种情况下,可能是您想要回复的群组聊天室
为了更好地理解不同的ID,例如,对不起,但是我应该考虑使用什么?您的答案与我的代码相同。很抱歉@canakkaleli,复制/粘贴错误。我已经修好了。查看
消息
上的聊天
和自
对象!你能粘贴错误信息吗?