diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index 02ef656a..e56eb814 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -103,8 +103,10 @@ class Bot(AbstractUser): del self.chats[id] except KeyError: pass - self.db.delete(BotChat.query.get(id)) - self.db.commit() + existing_chat = BotChat.query.get(id) + if existing_chat: + self.db.delete(existing_chat) + self.db.commit() async def _can_use_commands(self, chat, tgid): if tgid in self.tg_whitelist: