【问题标题】:Telegram Bot How to delete or remove a message or media from a channel or groupTelegram Bot 如何从频道或群组中删除或移除消息或媒体
【发布时间】:2016-05-18 02:57:45
【问题描述】:

我想知道一个像照片一样删除消息或文件的例子

没找到这方面的功能教程,

【问题讨论】:

  • 现在可以做啦!

标签: telegram telegram-bot


【解决方案1】:

目前 Telegram Bot API 中没有此类功能。

UPD 2017-05-19:有一个官方方法 deleteMessage,更多信息: https://core.telegram.org/bots/api#deletemessage

https://stackoverflow.com/a/43965602/1140438

【讨论】:

  • 有不使用bot API删除消息的方法:core.telegram.org/method/messages.deleteMessages
  • 谢谢@ihoru,这是否意味着机器人不能删除例如不正确的帖子?你确定吗?
  • 这方面有什么解决办法吗?
  • 其他管理员都不可能删除频道中的消息有什么解决办法吗?
  • @MohammadRezaEsmaeilzadeh 仍然不可用。
【解决方案2】:

bot api 中有两种方法可以让您编辑消息:editMessageTexteditMessageCaption。这并不理想,但您可以将其用作替代方案。

例如,将消息编辑为:

“此消息不可用。”

【讨论】:

    【解决方案3】:

    Bot API 3.0 正式支持 deleteMessage 方法。更多细节在这里: https://core.telegram.org/bots/api#deletemessage

    https://api.telegram.org/botTOKEN/deleteMessage?chat_id=CID&message_id=MID

    如您所见,有两个参数:chat_idmessage_id

    您可以删除 bot 的消息或除服务消息(例如加入/离开消息)之外的其他消息(如果 bot 是管理员)。

    1. 如果成功,它将返回以下 JSON 对象: {"ok":true,"result":true}

    2. 如果您尝试删除服务消息或其他用户的消息,但 bot 不是管理员: {"ok":false,"error_code":400,"description":"Bad Request: message can't be deleted"}.

    3. 如果您尝试删除不存在的消息或已删除的消息: {"ok":false,"error_code":400,"description":"Bad Request: message to delete not found"}

    【讨论】:

    • 好答案。你能举个例子如何在javaScript中管理这三种情况
    【解决方案4】:
    【解决方案5】:
    请检查下面的代码 sn-p!,下面的代码对我有用!
    String chatId = String.valueOf(callbackQuery.getMessage().getChatId());
    Integer messageId = callbackQuery.getMessage().getMessageId();
    DeleteMessage deleteMessage = new DeleteMessage(chatId, messageId);
    try {
      execute(deleteMessage);
    }catch(TelegramApiException tae) {
      throw new RuntimeException(tae);
    }
    

    【讨论】:

      【解决方案6】:

      您可以转发消息并保存消息 ID,然后删除该消息。如果你能做到,你的信息就存在。

      这样做:

      try:
         mes=bot.forward_message(chat_id=?,from_chat_id=?,message_id=?)
         bot.delete_message(chat_id=?,message_id=mes.id)
      except:
         print("your message deleted")
      

      【讨论】:

        猜你喜欢
        • 2017-11-28
        • 1970-01-01
        • 1970-01-01
        • 2021-09-22
        • 2021-11-15
        • 2019-03-02
        • 2018-06-06
        • 1970-01-01
        • 2020-10-01
        相关资源
        最近更新 更多