Skip to content

Commit

Permalink
Fixed bug when member was not in server
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanealV committed Aug 10, 2022
1 parent 0c4f26a commit 20681ab
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ async def handle_reaction(emoji, message, reaction_user):
elif str(emoji) == '❎':
await embed_actions.message_close()
elif str(emoji) == '⏲️':
ticket_user = guild.get_member(ticket['user'])
ticket_user = await bot.fetch_user(ticket['user'])
await embed_actions.message_timeout(ticket_user)

@bot.event
Expand Down
13 changes: 10 additions & 3 deletions utils/embed_reactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ async def message_reply(self):

ticket_user = self.guild.get_member(self.ticket['user'])

if not ticket_user:
await self.modmail_channel.send("Cannot reply to ticket as user is not in the server.")
return

cancel = await self.modmail_channel.send(embed=ticket_embed.reply_cancel(ticket_user))
await cancel.add_reaction('❎')

Expand Down Expand Up @@ -82,7 +86,10 @@ def reply_message(message):
async def message_close(self):
"""Sends close confirmation embed, and if confirmed, will close the ticket."""

ticket_user = self.guild.get_member(self.ticket['user'])
ticket_user = await self.bot.fetch_user(self.ticket['user'])

if not ticket_user:
ticket_user = "user"

confirmation = await self.modmail_channel.send(embed=ticket_embed.close_confirmation(ticket_user))
await confirmation.add_reaction('✅')
Expand Down Expand Up @@ -123,13 +130,13 @@ def timeout_check(reaction, user):
# Change below value to custom
timeout = datetime.datetime.now() + datetime.timedelta(days=1)
timestamp = int(timeout.timestamp())
await ticket_user.send(embed=ticket_embed.user_timeout(timestamp))
db.set_timeout(ticket_user.id, timestamp)
await self.modmail_channel.send('{0} has been successfully timed out for 24 hours. They will be able to message ModMail again after <t:{1}>.'.format(ticket_user, timestamp))
await ticket_user.send(embed=ticket_embed.user_timeout(timestamp))
except asyncio.TimeoutError:
pass
except discord.errors.Forbidden:
await self.modmail_channel.send("Could not send timeout message to specified user due to privacy settings. Timeout has not been set.")
pass
except Exception as e:
raise RuntimeError(e)

Expand Down

0 comments on commit 20681ab

Please sign in to comment.