gracefully handle not being able to message users

This commit is contained in:
Infinidoge 2025-01-01 01:18:40 -05:00
parent bd5706c0ce
commit cb227109f4
Signed by: Infinidoge
SSH key fingerprint: SHA256:GT2StvPQMMfFHyiiFJymQxfTG/z6EWLJ6NWItf5K5sA

View file

@ -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")