Skip to content

Commit 0df3d8a

Browse files
Implement error handling for DM messages (#460)
1 parent f18fc22 commit 0df3d8a

1 file changed

Lines changed: 29 additions & 24 deletions

File tree

cogs/strike.py

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -254,30 +254,35 @@ class BaseStrikeCog(TeXBotBaseCog):
254254
async def _send_strike_user_message(
255255
self, strike_user: discord.User | discord.Member, member_strikes: DiscordMemberStrikes
256256
) -> None:
257-
await strike_user.send(
258-
"Hi, a recent incident occurred in which you may have broken one or more of "
259-
f"the {self.bot.group_short_name} Discord server's rules.\n"
260-
"We have increased the number of strikes associated with your account "
261-
f"to {min(3, member_strikes.strikes)} and "
262-
"the corresponding moderation action will soon be applied to you. "
263-
"To find what moderation action corresponds to which strike level, "
264-
"you can view "
265-
f"the {self.bot.group_short_name} Discord server moderation document "
266-
f"[here](<{settings.MODERATION_DOCUMENT_URL}>)\nPlease ensure you have read "
267-
f"the rules in {await self.bot.get_mention_string(self.bot.rules_channel)} so "
268-
"that your future behaviour adheres to them."
269-
f"{
270-
(
271-
'\nBecause you now have been given 3 strikes, you have been banned from '
272-
f'the {self.bot.group_short_name} Discord server '
273-
f'and we have contacted {self.bot.group_moderation_contact} for '
274-
'further action & advice.'
275-
)
276-
if member_strikes.strikes >= 3
277-
else ''
278-
}\n\n"
279-
"A committee member will be in contact with you shortly, to discuss this further."
280-
)
257+
try:
258+
await strike_user.send(
259+
"Hi, a recent incident occurred in which you may have broken one or more of "
260+
f"the {self.bot.group_short_name} Discord server's rules.\n"
261+
"We have increased the number of strikes associated with your account "
262+
f"to {min(3, member_strikes.strikes)} and "
263+
"the corresponding moderation action will soon be applied to you. "
264+
"To find what moderation action corresponds to which strike level, "
265+
"you can view "
266+
f"the {self.bot.group_short_name} Discord server moderation document "
267+
f"[here](<{settings.MODERATION_DOCUMENT_URL}>)\nPlease ensure you have read "
268+
f"the rules in {await self.bot.get_mention_string(self.bot.rules_channel)} so "
269+
"that your future behaviour adheres to them."
270+
f"{
271+
(
272+
'\nBecause you now have been given 3 strikes, '
273+
'you have been banned from '
274+
f'the {self.bot.group_short_name} Discord server '
275+
f'and we have contacted {self.bot.group_moderation_contact} for '
276+
'further action & advice.'
277+
)
278+
if member_strikes.strikes >= 3
279+
else ''
280+
}\n\n"
281+
"A committee member will be in contact with you shortly, "
282+
"to discuss this further."
283+
)
284+
except discord.Forbidden:
285+
logger.warning("Failed to send strike message to %s", strike_user)
281286

282287
async def _confirm_perform_moderation_action(
283288
self,

0 commit comments

Comments
 (0)