Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 43 additions & 31 deletions modules/moderation/modmail.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,8 @@ def __init__(self: Self) -> None:
self.guild_id: int = None
self.forum_channel_id: int = None

# Setup all intents and call the discord.Client init call to start the bot
intents = discord.Intents.all()
intents.members = True
# Setup default intents and call the discord.Client init call to start the bot
intents = discord.Intents.default()
super().__init__(intents=intents)

@commands.Cog.listener()
Expand Down Expand Up @@ -201,37 +200,18 @@ async def on_message_edit(

await thread.send(embed=embed)

@commands.Cog.listener()
async def on_member_remove(self: Self, member: discord.Member) -> None:
"""Sends a message into a thread if the addressee left
async def get_member_object(self: Self, user_id: int) -> discord.Member:
"""This uses the modmail bot to fetch a given member by ID
This always uses the configured modmail guild

Args:
member (discord.Member): The member who left
"""
if member.id in active_threads:
thread = self.get_channel(active_threads[member.id])
embed = discord.Embed(
color=discord.Color.red(),
title="Member left",
description=f"{member.mention} has left the guild.",
)
await thread.send(embed=embed)

@commands.Cog.listener()
async def on_member_join(self: Self, member: discord.Member) -> None:
"""Sends a message into a thread if the addressee joined the guild with an active thread
user_id (int): The user ID to fetch the member of

Args:
member (discord.Member): The member who joined
Returns:
discord.Member: The member object obtained
"""
if member.id in active_threads:
thread = self.get_channel(active_threads[member.id])
embed = discord.Embed(
color=discord.Color.blue(),
title="Member joined",
description=f"{member.mention} has rejoined the guild.",
)
await thread.send(embed=embed)
guild = await self.fetch_guild(self.guild_id)
return await guild.fetch_member(user_id)


# Makes the Ts_client variable a global variable
Expand Down Expand Up @@ -690,7 +670,7 @@ async def reply_to_thread(
)

# Refetches the user from modmails client so it can reply to it instead of TS
user = Modmail_client.get_user(target_member.id)
user = await Modmail_client.get_member_object(target_member.id)

# Attachments is either None or a list of files, discord can handle either
await user.send(embed=embed, files=user_attachments)
Expand Down Expand Up @@ -1734,3 +1714,35 @@ async def thread_rule(
thread=interaction.channel,
anonymous=True,
)

@commands.Cog.listener()
async def on_member_remove(self: Self, member: discord.Member) -> None:
"""Sends a message into a thread if the addressee left

Args:
member (discord.Member): The member who left
"""
if member.id in active_threads:
thread = self.bot.get_channel(active_threads[member.id])
embed = discord.Embed(
color=discord.Color.red(),
title="Member left",
description=f"{member.mention} has left the guild.",
)
await thread.send(embed=embed)

@commands.Cog.listener()
async def on_member_join(self: Self, member: discord.Member) -> None:
"""Sends a message into a thread if the addressee joined the guild with an active thread

Args:
member (discord.Member): The member who joined
"""
if member.id in active_threads:
thread = self.bot.get_channel(active_threads[member.id])
embed = discord.Embed(
color=discord.Color.blue(),
title="Member joined",
description=f"{member.mention} has rejoined the guild.",
)
await thread.send(embed=embed)
Loading