将消息发送到频道-bot.send_message不再起作用

问题描述 投票:0回答:1

前一段时间,我曾经将消息发送到这样的频道:

def broadcast(bot, update):
    bot.send_message(channel_id, text)

我会用以下方式回复用户:

def reply(bot, update):
    update.message.reply_text(text)

现在,似乎CommandHandlers的参数已从(bot, update)更改为(update, context)。结果,我仍然可以使用update参数回复用户,如下所示:

def reply(update, context):
    update.message.reply_text(text)

但是我不能再将消息发送到频道。我该怎么办?

telegram telegram-bot python-telegram-bot
1个回答
0
投票

[From documentationbotcontext中可用。

那么,什么信息存储在CallbackContext上?参数标有星号的标记只会在特定的更新中设置。

  • bot
  • job_queue
  • update_queue
  • ...

因此函数,

def broadcast(bot, update):
    bot.send_message(channel_id, text)

可以这样重写:

def broadcast(update, context):
    context.bot.send_message(channel_id, text)
© www.soinside.com 2019 - 2024. All rights reserved.