Skip to content

Commit 70890d6

Browse files
committed
Template v5.1
* Added the `help` command once again * Created a group for the `warning` command, has following sub-commands: * `add` - Adds a warning to the user * `remove` - Removes a warning from the user * `list` - Lists all the warnings of the user
1 parent 251f4b4 commit 70890d6

File tree

11 files changed

+98
-20
lines changed

11 files changed

+98
-20
lines changed

UPDATES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
Here is the list of all the updates that I made on this template.
44

5+
### Version 5.1 (12 September 2022)
6+
7+
* Added the `help` command once again
8+
* Created a group for the `warning` command, has following sub-commands:
9+
* `add` - Adds a warning to the user
10+
* `remove` - Removes a warning from the user
11+
* `list` - Lists all the warnings of the user
12+
513
### Version 5.0 (20 August 2022)
614

715
> ⚠️ **Moved to discord.py 2.0 as it is now officially released**

bot.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
import asyncio

cogs/fun.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
import random

cogs/general.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
import platform
@@ -22,6 +22,24 @@ class General(commands.Cog, name="general"):
2222
def __init__(self, bot):
2323
self.bot = bot
2424

25+
@commands.hybrid_command(
26+
name="help",
27+
description="List all commands the bot has loaded."
28+
)
29+
async def help(self, context: Context) -> None:
30+
prefix = self.bot.config["prefix"]
31+
embed = discord.Embed(title="Help", description="List of available commands:", color=0x9C84EF)
32+
for i in self.bot.cogs:
33+
cog = self.bot.get_cog(i.lower())
34+
commands = cog.get_commands()
35+
data = []
36+
for command in commands:
37+
description = command.description.partition('\n')[0]
38+
data.append(f"{prefix}{command.name} - {description}")
39+
help_text = "\n".join(data)
40+
embed.add_field(name=i.capitalize(), value=f'```{help_text}```', inline=False)
41+
await context.send(embed=embed)
42+
2543
@commands.hybrid_command(
2644
name="botinfo",
2745
description="Get some useful (or not) information about the bot.",

cogs/moderation.py

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

9-
from doctest import debug_script
109
import discord
1110
from discord import app_commands
1211
from discord.ext import commands
@@ -152,14 +151,23 @@ async def ban(self, context: Context, user: discord.User, reason: str = "Not spe
152151
)
153152
await context.send(embed=embed)
154153

155-
@commands.hybrid_command(
156-
name="warn",
157-
description="Warns a user in the server.",
154+
@commands.hybrid_group(
155+
name="warning",
156+
description="Manage warnings of a user on a server.",
158157
)
159158
@commands.has_permissions(manage_messages=True)
160159
@checks.not_blacklisted()
160+
async def warning(self, context: Context) -> None:
161+
pass
162+
163+
@warning.command(
164+
name="add",
165+
description="Adds a warning to a user in the server.",
166+
)
167+
@checks.not_blacklisted()
168+
@commands.has_permissions(manage_messages=True)
161169
@app_commands.describe(user="The user that should be warned.", reason="The reason why the user should be warned.")
162-
async def warn(self, context: Context, user: discord.User, reason: str = "Not specified") -> None:
170+
async def warning_add(self, context: Context, user: discord.User, reason: str = "Not specified") -> None:
163171
"""
164172
Warns a user in his private messages.
165173
@@ -185,14 +193,38 @@ async def warn(self, context: Context, user: discord.User, reason: str = "Not sp
185193
# Couldn't send a message in the private messages of the user
186194
await context.send(f"{member.mention}, you were warned by **{context.author}**!\nReason: {reason}")
187195

188-
@commands.hybrid_command(
189-
name="warnings",
196+
@warning.command(
197+
name="remove",
198+
description="Removes a warning from a user in the server.",
199+
)
200+
@checks.not_blacklisted()
201+
@commands.has_permissions(manage_messages=True)
202+
@app_commands.describe(user="The user that should get their warning removed.", warn_id="The ID of the warning that should be removed.")
203+
async def warning_add(self, context: Context, user: discord.User, warn_id: int) -> None:
204+
"""
205+
Warns a user in his private messages.
206+
207+
:param context: The hybrid command context.
208+
:param user: The user that should get their warning removed.
209+
:param warn_id: The ID of the warning that should be removed.
210+
"""
211+
member = context.guild.get_member(user.id) or await context.guild.fetch_member(user.id)
212+
total = db_manager.remove_warn(warn_id, user.id, context.guild.id)
213+
embed = discord.Embed(
214+
title="User Warn Removed!",
215+
description=f"I've removed the warning **#{warn_id}** from **{member}**!\nTotal warns for this user: {total}",
216+
color=0x9C84EF
217+
)
218+
await context.send(embed=embed)
219+
220+
@warning.command(
221+
name="list",
190222
description="Shows the warnings of a user in the server.",
191223
)
192224
@commands.has_guild_permissions(manage_messages=True)
193225
@checks.not_blacklisted()
194226
@app_commands.describe(user="The user you want to get the warnings of.")
195-
async def warnings(self, context: Context, user: discord.User):
227+
async def warning_list(self, context: Context, user: discord.User):
196228
"""
197229
Shows the warnings of a user in the server.
198230
@@ -209,7 +241,7 @@ async def warnings(self, context: Context, user: discord.User):
209241
description = "This user has no warnings."
210242
else:
211243
for warning in warnings_list:
212-
description += f"• Warned by <@{warning[2]}>: **{warning[3]}** (<t:{warning[4]}>)\n"
244+
description += f"• Warned by <@{warning[2]}>: **{warning[3]}** (<t:{warning[4]}>) - Warn ID #{warning[5]}\n"
213245
embed.description = description
214246
await context.send(embed=embed)
215247

cogs/owner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
import json

cogs/template.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
from discord.ext import commands

database/schema.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ CREATE TABLE IF NOT EXISTS `blacklist` (
44
);
55

66
CREATE TABLE IF NOT EXISTS `warns` (
7+
`id` int(11) NOT NULL,
78
`user_id` varchar(20) NOT NULL,
89
`server_id` varchar(20) NOT NULL,
910
`moderator_id` varchar(20) NOT NULL,

exceptions/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
from discord.ext import commands

helpers/checks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.0
6+
Version: 5.1
77
"""
88

99
import json

0 commit comments

Comments
 (0)