前一段时间,我曾经将消息发送到这样的频道:
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)
但是我不能再将消息发送到频道。我该怎么办?
[From documentation,bot
在context
中可用。
那么,什么信息存储在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)