向频道发送消息-bot.end_Message不再起作用 [英] Sending messages to channels - bot.send_message no longer works
本文介绍了向频道发送消息-bot.end_Message不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
前一段时间,我经常这样向渠道发送消息:
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
中可用。
那么,哪些信息存储在Callback Context上呢?参数 标有星号的将仅在特定更新中设置。
- 机器人
- 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)
这篇关于向频道发送消息-bot.end_Message不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文