feat: Add context menu commands for moderation actions
Adds context menu commands for banning, kicking, timing out, and removing timeout for users directly from their profile. This provides a more convenient way to perform common moderation tasks.
This commit is contained in:
parent
10c05d6fa3
commit
c251fafd73
@ -1126,5 +1126,54 @@ class ModerationCog(commands.Cog):
|
||||
async def on_ready(self):
|
||||
print(f'{self.__class__.__name__} cog has been loaded.')
|
||||
|
||||
# Context menu commands must be defined at module level
|
||||
|
||||
@app_commands.context_menu(name="Ban User")
|
||||
async def ban_user_context_menu(interaction: discord.Interaction, member: discord.Member):
|
||||
"""Bans the selected user."""
|
||||
cog = interaction.client.get_cog("ModerationCog")
|
||||
if cog:
|
||||
# Call the existing ban callback with default reason and delete_days
|
||||
await cog.moderate_ban_callback(interaction, member, reason="Banned via context menu", delete_days=0)
|
||||
else:
|
||||
await interaction.response.send_message("Error: Moderation cog not found.", ephemeral=True)
|
||||
|
||||
@app_commands.context_menu(name="Kick User")
|
||||
async def kick_user_context_menu(interaction: discord.Interaction, member: discord.Member):
|
||||
"""Kicks the selected user."""
|
||||
cog = interaction.client.get_cog("ModerationCog")
|
||||
if cog:
|
||||
# Call the existing kick callback with default reason
|
||||
await cog.moderate_kick_callback(interaction, member, reason="Kicked via context menu")
|
||||
else:
|
||||
await interaction.response.send_message("Error: Moderation cog not found.", ephemeral=True)
|
||||
|
||||
@app_commands.context_menu(name="Timeout User")
|
||||
async def timeout_user_context_menu(interaction: discord.Interaction, member: discord.Member):
|
||||
"""Timeouts the selected user for a short duration."""
|
||||
cog = interaction.client.get_cog("ModerationCog")
|
||||
if cog:
|
||||
# For simplicity in context menu, apply a default short timeout (e.g., 5 minutes)
|
||||
# A more complex implementation might use a modal to ask for duration/reason
|
||||
await cog.moderate_timeout_callback(interaction, member, duration="5m", reason="Timed out via context menu")
|
||||
else:
|
||||
await interaction.response.send_message("Error: Moderation cog not found.", ephemeral=True)
|
||||
|
||||
@app_commands.context_menu(name="Remove Timeout")
|
||||
async def remove_timeout_context_menu(interaction: discord.Interaction, member: discord.Member):
|
||||
"""Removes timeout from the selected user."""
|
||||
cog = interaction.client.get_cog("ModerationCog")
|
||||
if cog:
|
||||
# Call the existing remove timeout callback with default reason
|
||||
await cog.moderate_remove_timeout_callback(interaction, member, reason="Timeout removed via context menu")
|
||||
else:
|
||||
await interaction.response.send_message("Error: Moderation cog not found.", ephemeral=True)
|
||||
|
||||
|
||||
async def setup(bot: commands.Bot):
|
||||
await bot.add_cog(ModerationCog(bot))
|
||||
cog = ModerationCog(bot)
|
||||
await bot.add_cog(cog)
|
||||
bot.tree.add_command(ban_user_context_menu)
|
||||
bot.tree.add_command(kick_user_context_menu)
|
||||
bot.tree.add_command(timeout_user_context_menu)
|
||||
bot.tree.add_command(remove_timeout_context_menu)
|
||||
|
Loading…
x
Reference in New Issue
Block a user