电报机器人是否可以从组中删除消息

Is that possible a telegram bot can remove messages from group

我想创建电报机器人。 它可以加入群组和删除群组中的消息。 电报机器人是否可以从群组中删除消息? 我搜索了一下,有些人说可以,有些人说不行

这已经过时了,请参阅


使用 Telegram 机器人 API? 没有,目前还没有这个功能

但是,如果您使用的是 Telegram API,则可以使用 messages.deleteMessages 方法,这需要您将消息 ID 列表作为参数提供给它。

检查这个 link,似乎新的 bot API 在一些限制下使其成为可能:
https://core.telegram.org/bots/api#deletemessage
以下详情来自电报API页面:

  • A message can only be deleted if it was sent less than 48 hours ago.
  • Bots can delete outgoing messages in groups and supergroups.
  • Bots granted can_post_messages permissions can delete outgoing messages in channels.
  • If the bot is an administrator of a group, it can delete any message there.
  • If the bot has can_delete_messages permission in a supergroup or a channel, it can delete any message there.

Returns 成功即为真。

您可以使用

bot.DeleteMessageAsync(chatId, messageId)

如果消息不再存在或者你的 messageId 错误,你应该尝试捕获它,

messageId 是您在 MessageEventArgs.Message、

中获得的 属性

注意:chatId 应该是 Group/Channel chatId 而不是发送它的用户的,在 MessageEventArgs.Message 的 Chat.Id 属性 中获取 ...