Skip to content

Commit

Permalink
Get or fetch member when trying to reply
Browse files Browse the repository at this point in the history
This fixes an issue where the member may not be in the cache
  • Loading branch information
ChrisLovering committed Dec 4, 2023
1 parent 88b5dff commit 191ef4b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 10 additions & 0 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,16 @@ async def get_or_fetch_user(self, id: int) -> discord.User:
"""
return self.get_user(id) or await self.fetch_user(id)

@staticmethod
async def get_or_fetch_member(guild: discord.Guild, member_id: int) -> typing.Optional[discord.Member]:
"""
Attempt to get a member from cache; on failure fetch from the API.
Returns:
The :obj:`discord.Member` or :obj:`None` to indicate the member could not be found.
"""
return guild.get_member(member_id) or await guild.fetch_member(member_id)

async def retrieve_emoji(self) -> typing.Tuple[str, str]:
sent_emoji = self.config["sent_emoji"]
blocked_emoji = self.config["blocked_emoji"]
Expand Down
8 changes: 7 additions & 1 deletion core/thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,13 @@ async def reply(
"""Returns List[user_dm_msg] and thread_channel_msg"""
if not message.content and not message.attachments and not message.stickers:
raise MissingRequiredArgument(DummyParam("msg"))
if not any(g.get_member(self.id) for g in self.bot.guilds):
for guild in self.bot.guilds:
try:
if await self.bot.get_or_fetch_member(guild, self.id):
break
except discord.NotFound:
pass
else:
return await message.channel.send(
embed=discord.Embed(
color=self.bot.error_color,
Expand Down

0 comments on commit 191ef4b

Please sign in to comment.