Skip to content

Commit dd26c75

Browse files
Add exception handling
1 parent d6f6c50 commit dd26c75

1 file changed

Lines changed: 17 additions & 18 deletions

File tree

cogs/strike.py

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
from typing import TYPE_CHECKING
99

1010
import discord
11-
12-
# noinspection SpellCheckingInspection
1311
from asyncstdlib.builtins import any as asyncany
1412
from discord.ui import View
1513

@@ -275,20 +273,23 @@ async def _send_strike_user_message(
275273

276274
actual_strike_amount: int = min(3, member_strikes.strikes)
277275

278-
await strike_user.send(
279-
"Hi, a recent incident occurred in which you may have broken one or more of "
280-
f"the {self.bot.group_short_name} Discord server's rules.\n"
281-
"We have increased the number of strikes associated with your account "
282-
f"to {actual_strike_amount} and "
283-
"the corresponding moderation action will soon be applied to you. "
284-
"To find what moderation action corresponds to which strike level, "
285-
"you can view "
286-
f"the {self.bot.group_short_name} Discord server moderation document "
287-
f"[here](<{settings.MODERATION_DOCUMENT_URL}>)\nPlease ensure you have read "
288-
f"the rules in {rules_channel_mention} so that your future behaviour adheres "
289-
f"to them.{includes_ban_message}\n\nA committee member will be in contact "
290-
"with you shortly, to discuss this further.",
291-
)
276+
try:
277+
await strike_user.send(
278+
"Hi, a recent incident occurred in which you may have broken one or more of "
279+
f"the {self.bot.group_short_name} Discord server's rules.\n"
280+
"We have increased the number of strikes associated with your account "
281+
f"to {actual_strike_amount} and "
282+
"the corresponding moderation action will soon be applied to you. "
283+
"To find what moderation action corresponds to which strike level, "
284+
"you can view "
285+
f"the {self.bot.group_short_name} Discord server moderation document "
286+
f"[here](<{settings.MODERATION_DOCUMENT_URL}>)\nPlease ensure you have read "
287+
f"the rules in {rules_channel_mention} so that your future behaviour adheres "
288+
f"to them.{includes_ban_message}\n\nA committee member will be in contact "
289+
"with you shortly, to discuss this further.",
290+
)
291+
except discord.Forbidden:
292+
logger.warning("Unable to send strike message to %s", strike_user)
292293

293294
async def _confirm_perform_moderation_action(
294295
self,
@@ -392,7 +393,6 @@ async def _confirm_increase_strike(
392393
)
393394

394395
if not perform_action:
395-
# noinspection SpellCheckingInspection
396396
await message_sender_component.send(
397397
content=(
398398
f"{confirm_strike_message}\n"
@@ -648,7 +648,6 @@ async def _confirm_manual_add_strike(
648648
"with number of strikes**"
649649
),
650650
)
651-
# noinspection SpellCheckingInspection
652651
await out_of_sync_ban_confirmation_message.edit(
653652
content=(
654653
f"Successfully banned {strike_user.mention}.\n"

0 commit comments

Comments
 (0)