From cb227109f48197143e023edf71761a37add16fc7 Mon Sep 17 00:00:00 2001 From: Infinidoge Date: Wed, 1 Jan 2025 01:18:40 -0500 Subject: [PATCH] gracefully handle not being able to message users --- nomen/notifications.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/nomen/notifications.py b/nomen/notifications.py index f1a0bf3..b69a4f3 100644 --- a/nomen/notifications.py +++ b/nomen/notifications.py @@ -5,6 +5,7 @@ from typing import Union from disnake import Embed, Member, Thread, User from disnake.abc import GuildChannel +from disnake.errors import Forbidden from disnake.ext.commands import Cog, group, guild_only from .utils import can_view, confirm, test_keyword @@ -64,10 +65,16 @@ async def handle_notification(db_updates, ctx, message, keyword, user_id, use_em icon_url=message.author.display_avatar, ) - await member.send(header, embed=embed) + try: + await member.send(header, embed=embed) + except Forbidden: + log.warning("Cannot send messages to this user") else: log.debug("Sending plain message") - await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer))) + try: + await member.send("\n".join((header, indent(message.content, "> ", lambda line: True).strip(), footer))) + except Forbidden: + log.warning("Cannot send messages to this user") log.debug("Sent")