Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reminder): reminders possibly never sent
Browse files Browse the repository at this point in the history
ZRunner committed Nov 30, 2023
1 parent 8ea3516 commit 0205f37
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions libs/tasks_handler/tasks_handler.py
Original file line number Diff line number Diff line change
@@ -133,6 +133,15 @@ async def check_tasks(self):
self.bot.dispatch("error", err)
self.bot.log.error("[role-grant_task] Unable to remove temporary role: %s", err)

async def _get_or_fetch_user(self, user_id: int):
if user := self.bot.get_user(user_id):
return user
try:
return await self.bot.fetch_user(user_id)
except discord.NotFound:
pass
return None

async def task_timer(self, task: dict) -> bool:
"""Send a reminder
Returns True if the reminder has been sent"""
@@ -145,12 +154,12 @@ async def task_timer(self, task: dict) -> bool:
channel = guild.get_channel_or_thread(task["channel"])
member = await guild.fetch_member(task["user"])
# if channel has been deleted, or if member left the guild, we send it in DM
if channel is None or member is None:
channel = self.bot.get_user(task["user"])
if channel is None or member is None or not channel.permissions_for(guild.me).send_messages:
channel = await self._get_or_fetch_user(task["user"])
if channel is None:
return False
else:
channel = self.bot.get_user(task["user"])
channel = await self._get_or_fetch_user(task["user"])
if not channel:
return False
user = channel if isinstance(channel, discord.User) else self.bot.get_user(task["user"])

0 comments on commit 0205f37

Please sign in to comment.