Skip to content

Commit d4d68d3

Browse files
committed
Feat: Automatically remove welcome message after 50000ms (50s)
1 parent 36a485c commit d4d68d3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

tg_bot/modules/welcome.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from telegram import Message, Chat, Update, Bot, User
77
from telegram import ParseMode, InlineKeyboardMarkup
88
from telegram.error import BadRequest
9-
from telegram.ext import MessageHandler, Filters, CommandHandler, run_async, JobQueue
9+
from telegram.ext import MessageHandler, Filters, CommandHandler, run_async
1010
from telegram.utils.helpers import mention_markdown, mention_html, escape_markdown
1111

1212
import tg_bot.modules.sql.users_sql as user_sql
@@ -216,6 +216,7 @@ def new_member(bot: Bot, update: Update):
216216
keyboard,
217217
sql.DEFAULT_WELCOME.format(first=first_name),
218218
) # type: Optional[Message]
219+
delete_welcome_message(bot, sent.message_id, 50000)
219220

220221
else:
221222
# BEGINNING THE BAN
@@ -270,6 +271,14 @@ def new_member(bot: Bot, update: Update):
270271
sql.set_clean_welcome(chat.id, sent.message_id)
271272

272273

274+
@run_async
275+
def delete_welcome_message(bot: Bot, update: Update, message_id: Message, timeout: int):
276+
# Very very very ugly way to handle a remove message after a timeout
277+
time.sleep(timeout)
278+
chat = update.effective_chat
279+
bot.delete_message(chat.id, message_id)
280+
281+
273282
@run_async
274283
def left_member(bot: Bot, update: Update):
275284
chat = update.effective_chat # type: Optional[Chat]

0 commit comments

Comments
 (0)