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

时间:2019-10-15 16:45:29

标签: telegram telegram-bot python-telegram-bot

前一阵子,我曾经将消息发送到这样的频道:

UPDATE dbo.tb_Push SET
    [Processed] = @piProcessed,
    [OOS] = @piOOS,
    [Error] = @piError
WHERE
    Price_Push_SID = @piPricePushSid;

我会用以下方式回复用户

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

但是我无法再将消息发送到某个频道。我该怎么办?

2 个答案:

答案 0 :(得分:1)

From documentationbotcontext中可用。

  

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

     
      
  • 机器人
  •   
  • 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)

答案 1 :(得分:0)

如上所述botcontext中可用,因此可以选择功能

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

可以改写为

def broadcast(update, context):
    bot = context.bot
    bot.send_message(channel_id, text)
相关问题