Skip to content

Commit d84df59

Browse files
committed
Template v2.1
Added features: - Small description to all commands - Intents when creating the bot Edited features: - Made the help command dynamic
1 parent 688926d commit d84df59

File tree

9 files changed

+93
-71
lines changed

9 files changed

+93
-71
lines changed

LICENSE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@
186186
same "printed page" as the copyright notice for easier
187187
identification within third-party archives.
188188

189-
Copyright 2020 Krypton
189+
Copyright 2021 Krypton
190190

191191
Licensed under the Apache License, Version 2.0 (the "License");
192192
you may not use this file except in compliance with the License.

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ python bot.py
7373

7474
If you have any issues or questions of how to code a specific command, you can:
7575

76-
* Join my discord server [here](https://discord.gg/xkWRGBY)
76+
* Join my discord server [here](https://discord.gg/HzJ3Gfr)
7777
* Post them [here](https://github.com/kkrypt0nn/Python-Discord-Bot-Template/issues)
7878

7979
Me or other people will take their time to answer and help you.
@@ -84,7 +84,7 @@ We use [SemVer](http://semver.org) for versioning. For the versions available, s
8484

8585
## Bots who used this template
8686

87-
*DM Krypton#2188 to get yourself in this list*
87+
*DM Krypton#7331 to get yourself in this list*
8888

8989
## License
9090

UPDATES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Updates List
22
Here is the list of all the updates that I made on this template.
33

4+
### Version 2.1
5+
* Made the help command dynamic
6+
* Added a small description to all commands
7+
* Added intents when creating the bot
8+
49
### Version 2.0
510
* Added cogs
611
* Added f-strings and removed `.format()`

bot.py

Lines changed: 12 additions & 6 deletions
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: 2.0
6+
Version: 2.1
77
"""
88

99
import discord, asyncio, os, platform, sys
@@ -19,12 +19,11 @@
1919
For more information about intents, please go to the following websites:
2020
https://discordpy.readthedocs.io/en/latest/intents.html
2121
https://discordpy.readthedocs.io/en/latest/intents.html#privileged-intents
22-
"""
23-
intents = discord.Intents().default()
22+
23+
24+
Default Intents:
2425
intents.messages = True
2526
intents.reactions = True
26-
intents.presences = True
27-
intents.members = True
2827
intents.guilds = True
2928
intents.emojis = True
3029
intents.bans = True
@@ -39,7 +38,14 @@
3938
intents.invites = True
4039
intents.voice_states = False
4140
intents.webhooks = False
42-
41+
42+
Privileged Intents (Needs to be enabled on dev page):
43+
intents.presences = True
44+
intents.members = True
45+
"""
46+
47+
intents = discord.Intents.default()
48+
4349
bot = Bot(command_prefix=config.BOT_PREFIX, intents=intents)
4450

4551
# The code in this even is executed when the bot is ready

cogs/general.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def __init__(self, bot):
1111

1212
@commands.command(name="info", aliases=["botinfo"])
1313
async def info(self, context):
14+
"""
15+
Get some useful (or not) information about the bot.
16+
"""
1417
embed = discord.Embed(
1518
description="Used Krypton's template",
1619
color=0x00FF00
@@ -40,6 +43,9 @@ async def info(self, context):
4043

4144
@commands.command(name="serverinfo")
4245
async def serverinfo(self, context):
46+
"""
47+
Get some useful (or not) information about the server.
48+
"""
4349
server = context.message.guild
4450
roles = [x.name for x in server.roles]
4551
role_length = len(roles)
@@ -87,6 +93,9 @@ async def serverinfo(self, context):
8793

8894
@commands.command(name="ping")
8995
async def ping(self, context):
96+
"""
97+
Check if the bot is alive.
98+
"""
9099
embed = discord.Embed(
91100
color=0x00FF00
92101
)
@@ -102,16 +111,25 @@ async def ping(self, context):
102111

103112
@commands.command(name="invite")
104113
async def invite(self, context):
114+
"""
115+
Get the invite link of the bot to be able to invite it.
116+
"""
105117
await context.send("I sent you a private message!")
106118
await context.author.send(f"Invite me by clicking here: https://discordapp.com/oauth2/authorize?&client_id={config.APPLICATION_ID}&scope=bot&permissions=8")
107119

108120
@commands.command(name="server")
109121
async def server(self, context):
122+
"""
123+
Get the invite link of the discord server of the bot for some support.
124+
"""
110125
await context.send("I sent you a private message!")
111-
await context.author.send("Join my discord server by clicking here: https://discord.gg/Vddcy76")
126+
await context.author.send("Join my discord server by clicking here: https://discord.gg/HzJ3Gfr")
112127

113128
@commands.command(name="poll")
114129
async def poll(self, context, *args):
130+
"""
131+
Create a poll where members can vote.
132+
"""
115133
poll_title = " ".join(args)
116134
embed = discord.Embed(
117135
title="A new poll has been created!",
@@ -128,6 +146,9 @@ async def poll(self, context, *args):
128146

129147
@commands.command(name="8ball")
130148
async def eight_ball(self, context, *args):
149+
"""
150+
Ask any question to the bot.
151+
"""
131152
answers = ['It is certain.', 'It is decidedly so.', 'You may rely on it.', 'Without a doubt.',
132153
'Yes - definitely.', 'As I see, yes.', 'Most likely.', 'Outlook good.', 'Yes.',
133154
'Signs point to yes.', 'Reply hazy, try again.', 'Ask again later.', 'Better not tell you now.',
@@ -145,6 +166,9 @@ async def eight_ball(self, context, *args):
145166

146167
@commands.command(name="bitcoin")
147168
async def bitcoin(self, context):
169+
"""
170+
Get the current price of bitcoin.
171+
"""
148172
url = "https://api.coindesk.com/v1/bpi/currentprice/BTC.json"
149173
# Async HTTP request
150174
async with aiohttp.ClientSession() as session:

cogs/help.py

Lines changed: 14 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -11,66 +11,20 @@ def __init__(self, bot):
1111

1212
@commands.command(name="help")
1313
async def help(self, context):
14-
# Note that commands made only for the owner of the bot are not listed here.
15-
embed = discord.Embed(
16-
title="Bot",
17-
description="List of commands are:",
18-
color=0x00FF00
19-
)
20-
embed.add_field(
21-
name="Invite",
22-
value=f"Usage: {config.BOT_PREFIX}invite",
23-
inline=False
24-
)
25-
embed.add_field(
26-
name="Server",
27-
value=f"Usage: {config.BOT_PREFIX}server",
28-
inline=False
29-
)
30-
embed.add_field(
31-
name="Poll",
32-
value=f"Usage: {config.BOT_PREFIX}poll <Idea>",
33-
inline=False
34-
)
35-
embed.add_field(
36-
name="8ball",
37-
value=f"Usage: {config.BOT_PREFIX}8ball <Question>",
38-
inline=False)
39-
embed.add_field(
40-
name="Bitcoin",
41-
value=f"Usage: {config.BOT_PREFIX}bitcoin",
42-
inline=False
43-
)
44-
embed.add_field(
45-
name="Info",
46-
value=f"Usage: {config.BOT_PREFIX}info",
47-
inline=False
48-
)
49-
embed.add_field(
50-
name="Kick",
51-
value=f"Usage: {config.BOT_PREFIX}kick <User> <Reason>",
52-
inline=False
53-
)
54-
embed.add_field(
55-
name="Ban",
56-
value=f"Usage: {config.BOT_PREFIX}ban <User> <Reason>",
57-
inline=False
58-
)
59-
embed.add_field(
60-
name="Warn",
61-
value=f"Usage: {config.BOT_PREFIX}warn <User> <Reason>",
62-
inline=False
63-
)
64-
embed.add_field(
65-
name="Purge",
66-
value=f"Usage: {config.BOT_PREFIX}purge <Number>",
67-
inline=False
68-
)
69-
embed.add_field(
70-
name="Help",
71-
value=f"Usage: {config.BOT_PREFIX}help",
72-
inline=False
73-
)
14+
"""
15+
List all commands from every Cog the bot has loaded.
16+
"""
17+
prefix = config.BOT_PREFIX
18+
if not isinstance(prefix, str):
19+
prefix = prefix[0]
20+
embed = discord.Embed(title="Help", description="List of available commands:", color=0x00FF00)
21+
for i in self.bot.cogs:
22+
cog = self.bot.get_cog(i.lower())
23+
commands = cog.get_commands()
24+
command_list = [command.name for command in commands]
25+
command_description = [command.help for command in commands]
26+
help_text = '\n'.join(f'{prefix}{n} - {h}' for n, h in zip(command_list, command_description))
27+
embed.add_field(name=i.capitalize(), value=f'```{help_text}```', inline=False)
7428
await context.send(embed=embed)
7529

7630
def setup(bot):

cogs/moderation.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def __init__(self, bot):
1111

1212
@commands.command(name='kick', pass_context=True)
1313
async def kick(self, context, member: discord.Member, *args):
14+
"""
15+
Kick a user out of the server.
16+
"""
1417
if context.message.author.guild_permissions.kick_members:
1518
if member.guild_permissions.administrator:
1619
embed = discord.Embed(
@@ -55,6 +58,9 @@ async def kick(self, context, member: discord.Member, *args):
5558

5659
@commands.command(name="nick")
5760
async def nick(self, context, member: discord.Member, *, name: str):
61+
"""
62+
Change the nickname of a user on a server.
63+
"""
5864
if context.message.author.guild_permissions.administrator:
5965
try:
6066
if name.lower() == "!reset":
@@ -83,6 +89,9 @@ async def nick(self, context, member: discord.Member, *, name: str):
8389

8490
@commands.command(name="ban")
8591
async def ban(self, context, member: discord.Member, *args):
92+
"""
93+
Bans a user from the server.
94+
"""
8695
if context.message.author.guild_permissions.administrator:
8796
try:
8897
if member.guild_permissions.administrator:
@@ -123,6 +132,9 @@ async def ban(self, context, member: discord.Member, *args):
123132

124133
@commands.command(name="warn")
125134
async def warn(self, context, member: discord.Member, *args):
135+
"""
136+
Warns a user in his private messages.
137+
"""
126138
if context.message.author.guild_permissions.administrator:
127139
reason = " ".join(args)
128140
embed = discord.Embed(
@@ -149,6 +161,9 @@ async def warn(self, context, member: discord.Member, *args):
149161

150162
@commands.command(name="purge")
151163
async def purge(self, context, number):
164+
"""
165+
Delete a number of messages.
166+
"""
152167
if context.message.author.guild_permissions.administrator:
153168
purged_messages = await context.message.channel.purge(limit=number)
154169
embed = discord.Embed(

cogs/owner.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ def __init__(self, bot):
1111

1212
@commands.command(name="shutdown")
1313
async def shutdown(self, context):
14+
"""
15+
Make the bot shutdown
16+
"""
1417
if context.message.author.id in config.OWNERS:
1518
embed = discord.Embed(
1619
description="Shutting down. Bye! :wave:",
@@ -29,6 +32,9 @@ async def shutdown(self, context):
2932

3033
@commands.command(name="say", aliases=["echo"])
3134
async def say(self, context, *, args):
35+
"""
36+
The bot will say anything you want.
37+
"""
3238
if context.message.author.id in config.OWNERS:
3339
await context.send(args)
3440
else:
@@ -41,6 +47,9 @@ async def say(self, context, *, args):
4147

4248
@commands.command(name="embed")
4349
async def embed(self, context, *, args):
50+
"""
51+
The bot will say anything you want, but within embeds.
52+
"""
4453
if context.message.author.id in config.OWNERS:
4554
embed = discord.Embed(
4655
description=args,
@@ -57,6 +66,9 @@ async def embed(self, context, *, args):
5766

5867
@commands.group(name="blacklist")
5968
async def blacklist(self, context):
69+
"""
70+
Lets you add or remove a user from not being able to use the bot.
71+
"""
6072
if context.invoked_subcommand is None:
6173
embed = discord.Embed(
6274
title=f"There are currently {len(config.BLACKLIST)} blacklisted IDs",
@@ -67,6 +79,9 @@ async def blacklist(self, context):
6779

6880
@blacklist.command(name="add")
6981
async def blacklist_add(self, context, member: discord.Member):
82+
"""
83+
Lets you add a user from not being able to use the bot.
84+
"""
7085
if context.message.author.id in config.OWNERS:
7186
userID = member.id
7287
try:
@@ -97,6 +112,9 @@ async def blacklist_add(self, context, member: discord.Member):
97112

98113
@blacklist.command(name="remove")
99114
async def blacklist_remove(self, context, member: discord.Member):
115+
"""
116+
Lets you remove a user from not being able to use the bot.
117+
"""
100118
if context.message.author.id in config.OWNERS:
101119
userID = member.id
102120
try:

config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@
77
# Default cogs that I have created for the template
88
STARTUP_COGS = [
99
"cogs.general", "cogs.help", "cogs.moderation", "cogs.owner",
10-
]
10+
]

0 commit comments

Comments
 (0)