mirror of
https://github.com/alterware/aw-bot.git
synced 2025-11-18 00:52:09 +00:00
chore: fix exception handling
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from bot.utils import aware_utcnow
|
from bot.utils import aware_utcnow
|
||||||
|
from bot.log import logger
|
||||||
|
|
||||||
|
import discord
|
||||||
|
|
||||||
|
|
||||||
async def handle_reaction_add(reaction, user, bot):
|
async def handle_reaction_add(reaction, user, bot):
|
||||||
# Ignore reactions from the bot itself
|
|
||||||
if user == bot.user:
|
if user == bot.user:
|
||||||
return
|
return
|
||||||
|
|
||||||
@@ -22,12 +24,22 @@ async def handle_reaction_add(reaction, user, bot):
|
|||||||
if reaction.message.reference is None:
|
if reaction.message.reference is None:
|
||||||
return
|
return
|
||||||
|
|
||||||
original_message = await reaction.message.channel.fetch_message(
|
try:
|
||||||
reaction.message.reference.message_id
|
original_message = await reaction.message.channel.fetch_message(
|
||||||
)
|
reaction.message.reference.message_id
|
||||||
|
)
|
||||||
|
except discord.NotFound:
|
||||||
|
logger.error(
|
||||||
|
"Error while trying to fetch message: referenced message was deleted or unavailable"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
except discord.Forbidden:
|
||||||
|
logger.error(
|
||||||
|
"Error while trying to fetch message: Bot doesn't have permissions to read that message/channel"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
if original_message.author == user:
|
if original_message.author == user:
|
||||||
await reaction.message.delete()
|
await reaction.message.delete()
|
||||||
else:
|
else:
|
||||||
# If the user is not the original author, remove their reaction
|
|
||||||
await reaction.remove(user)
|
await reaction.remove(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user