Skip to content
This repository was archived by the owner on Feb 7, 2026. It is now read-only.

Commit f054d94

Browse files
authored
Merge pull request #266 from PyBotDevs/move-moderation-commands-to-new-cog
Move existing moderation commands to new cog
2 parents 2048b97 + 10d145a commit f054d94

2 files changed

Lines changed: 51 additions & 38 deletions

File tree

cogs/moderation.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Imports
2+
import discord
3+
from discord import option, ApplicationContext
4+
from discord.ext import commands
5+
6+
# Commands
7+
class Moderation(commands.Cog):
8+
def __init__(self, bot):
9+
self.bot = bot
10+
11+
@commands.slash_command(
12+
name='kick',
13+
description='Kicks a member from this server.'
14+
)
15+
@option(name="user", description="Who do you want to kick?", type=discord.User)
16+
@option(name="reason", description="Why do you want to kick the user?", type=str, default=None)
17+
@commands.cooldown(1, 3, commands.BucketType.user)
18+
async def kick(self, ctx: ApplicationContext, user, reason=None):
19+
if not ctx.author.guild_permissions.kick_members: return await ctx.respond('https://tenor.com/view/oh-yeah-high-kick-take-down-fight-gif-14272509')
20+
else:
21+
try:
22+
if reason is None: await user.kick()
23+
else: await user.kick(reason=reason)
24+
await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}'))
25+
except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red()))
26+
27+
@commands.slash_command(
28+
name='ban',
29+
description='Bans a member from this server.'
30+
)
31+
@option(name="user", description="Who do you want to ban?", type=discord.User)
32+
@option(name="reason", description="Why you want to ban the user?", type=str, default=None)
33+
@commands.cooldown(1, 3, commands.BucketType.user)
34+
async def ban(self, ctx: ApplicationContext, user, reason=None):
35+
if not ctx.author.guild_permissions.ban_members: return await ctx.respond('https://tenor.com/view/thor-strike-admin-ban-admin-ban-gif-22545175')
36+
else:
37+
try:
38+
if reason is None: await user.ban()
39+
else: await user.ban(reason=reason)
40+
await ctx.respond(embed=discord.Embed(title=f'{user} has been banned.', description=f'Reason: {str(reason)}'))
41+
except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red()))
42+
43+
# Initialization
44+
def setup(bot): bot.add_cog(Moderation(bot))

main.py

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -224,38 +224,6 @@ async def sync(ctx: ApplicationContext):
224224
print(e)
225225
await ctx.respond('An error occured while resyncing. Check console.', ephemeral=True)
226226

227-
@client.slash_command(
228-
name='kick',
229-
description='Kicks a member from this server.'
230-
)
231-
@option(name="user", description="Who do you want to kick?", type=discord.User)
232-
@option(name="reason", description="Why do you want to kick the user?", type=str, default=None)
233-
@commands.cooldown(1, 3, commands.BucketType.user)
234-
async def kick(ctx: ApplicationContext, user, reason=None):
235-
if not ctx.author.guild_permissions.kick_members: return await ctx.respond('https://tenor.com/view/oh-yeah-high-kick-take-down-fight-gif-14272509')
236-
else:
237-
try:
238-
if reason is None: await user.kick()
239-
else: await user.kick(reason=reason)
240-
await ctx.respond(embed=discord.Embed(title=f'{user} has been kicked.', description=f'Reason: {str(reason)}'))
241-
except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red()))
242-
243-
@client.slash_command(
244-
name='ban',
245-
description='Bans a member from this server.'
246-
)
247-
@option(name="user", description="Who do you want to ban?", type=discord.User)
248-
@option(name="reason", description="Why you want to ban the user?", type=str, default=None)
249-
@commands.cooldown(1, 3, commands.BucketType.user)
250-
async def ban(ctx: ApplicationContext, user, reason=None):
251-
if not ctx.author.guild_permissions.ban_members: return await ctx.respond('https://tenor.com/view/thor-strike-admin-ban-admin-ban-gif-22545175')
252-
else:
253-
try:
254-
if reason is None: await user.ban()
255-
else: await user.ban(reason=reason)
256-
await ctx.respond(embed=discord.Embed(title=f'{user} has been banned.', description=f'Reason: {str(reason)}'))
257-
except Exception: await ctx.respond(embed=discord.Embed(title='Well, something happened...', description='Either I don\'t have permission to do this, or my role isn\'t high enough.', color=discord.Colour.red()))
258-
259227
# Cog Commands (these cannot be moved into a cog)
260228
cogs = client.create_group("cog", "Commands for working with isobot cogs.")
261229

@@ -318,13 +286,14 @@ async def reload(ctx: ApplicationContext, cog: str):
318286

319287
# Initialization
320288
active_cogs = [
321-
"economy",
289+
"economy",
322290
"maths",
323-
"reddit",
324-
"minigames",
325-
"automod",
326-
"isobank",
327-
"levelling",
291+
"reddit",
292+
"moderation",
293+
"minigames",
294+
"automod",
295+
"isobank",
296+
"levelling",
328297
"fun",
329298
"utils",
330299
"afk"

0 commit comments

Comments
 (0)