From 85577dd8b9cba1c4e5fd0a2104282d6f1861913b Mon Sep 17 00:00:00 2001 From: bursa-pastoris Date: Tue, 30 May 2023 04:12:24 +0200 Subject: [PATCH] Delete message with /epiphony command --- albatrobot.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/albatrobot.py b/albatrobot.py index 91a765b..028c6b6 100644 --- a/albatrobot.py +++ b/albatrobot.py @@ -32,7 +32,7 @@ import Levenshtein import psutil from rolldice import roll_dice, rolldice from telegram import BotCommand -from telegram.constants import ChatAction, ChatType, ParseMode +from telegram.constants import ChatAction, ChatMemberStatus, ChatType, ParseMode from constants import * @@ -391,6 +391,15 @@ async def epiphony(update, context): voice=open(voice_file,'rb'), reply_to_message_id=update.effective_message.reply_to_message.message_id if update.effective_message.reply_to_message else None) + bot_data = await context.bot.get_me() + bot_chatmember = await context.bot.get_chat_member( + chat_id=update.effective_chat.id, + user_id=bot_data.id) + if (bot_chatmember.status == ChatMemberStatus.ADMINISTRATOR + and bot_chatmember.can_delete_messages): + await context.bot.delete_message( + chat_id=update.effective_chat.id, + message_id=update.effective_message.message_id) async def roll(update, context):