diff --git a/bots/modules/ping.py b/bots/modules/ping.py index b781c15..e6bc05b 100644 --- a/bots/modules/ping.py +++ b/bots/modules/ping.py @@ -1,6 +1,7 @@ from django.db import models from jsonfield import JSONField from telegram import Update +from telegram.error import BadRequest from telegram.ext import Dispatcher, CallbackContext, CommandHandler from telegram.utils.helpers import mention_html @@ -58,8 +59,11 @@ class PingBotModuleConfig(TelegramBotModuleConfig): return update.effective_message.reply_text(self.no_users_text) mentions = [] for uid in cat.user_ids: - member = ctx.bot.get_chat_member(update.effective_chat.id, uid) - mentions.append(mention_html(uid, '#{} [{}]'.format(uid, member.user.full_name))) + try: + member = ctx.bot.get_chat_member(update.effective_chat.id, uid) + mentions.append(mention_html(uid, '#{} [{}]'.format(uid, member.user.full_name))) + except BadRequest: + cat.remove_user(uid) update.effective_message.reply_html(self.message_template.format(mentions='; '.join(mentions))) def categories_handler(self, update: Update, ctx: CallbackContext):