gracefully handle not being able to message users
This commit is contained in:
parent
bd5706c0ce
commit
cb227109f4
1 changed files with 9 additions and 2 deletions
|
@ -5,6 +5,7 @@ from typing import Union
|
||||||
|
|
||||||
from disnake import Embed, Member, Thread, User
|
from disnake import Embed, Member, Thread, User
|
||||||
from disnake.abc import GuildChannel
|
from disnake.abc import GuildChannel
|
||||||
|
from disnake.errors import Forbidden
|
||||||
from disnake.ext.commands import Cog, group, guild_only
|
from disnake.ext.commands import Cog, group, guild_only
|
||||||
|
|
||||||
from .utils import can_view, confirm, test_keyword
|
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,
|
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:
|
else:
|
||||||
log.debug("Sending plain message")
|
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")
|
log.debug("Sent")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue