Skip to content

Commit e0b93ad

Browse files
committed
Template v2.7
* Added a check for `commands.MissingRequiredArgument` in the error handler * Added a disclaimer section in the [README](README.md) file * Added the latency of the bot in the `ping` command * Created the [TODO list](TODO.md) file * Fixed some error embeds having success (green) colors * Removed an unnecessary `self.bot.logout()` statement * Removed the `dick` command, as I want to keep this template safe for work * Renamed the names of the arguments in some commands * The bot now **tries** to send an embed in the private message of the command author for the `invite` and `server` commands, if this was not successful it will be sent in the channel
1 parent 0bd9008 commit e0b93ad

File tree

10 files changed

+138
-66
lines changed

10 files changed

+138
-66
lines changed

README.md

+10-6
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ If you need some help for something, do not hesitate to join my discord server [
3838

3939
All the updates of the template are available [here](UPDATES.md).
4040

41+
## Disclaimer
42+
43+
**Nothing** is being saved during runtime in the configuration file, please take a look at the [TODO file](TODO.md) to
44+
know if this has been implemented.
45+
46+
Please do not open issues or pull requests about things that are written in the [TODO file](TODO.md), they are **
47+
already** under work for the version 3.0 of the template.
48+
4149
## How to download it
4250

4351
This repository is now a template, on the top left you can simply click on "**Use this template**" to create a GitHub
@@ -101,10 +109,6 @@ If you have just installed python today, then you just need to use the following
101109
python bot.py
102110
```
103111

104-
## Built With
105-
106-
* [Python 3.8](https://www.python.org/)
107-
108112
## Issues or Questions
109113

110114
If you have any issues or questions of how to code a specific command, you can:
@@ -119,9 +123,9 @@ Me or other people will take their time to answer and help you.
119123
We use [SemVer](http://semver.org) for versioning. For the versions available, see
120124
the [tags on this repository](https://github.com/kkrypt0nn/Python-Discord-Bot-Template/tags).
121125

122-
## Bots who used this template
126+
## Built With
123127

124-
*DM Krypton#7331 to get yourself in this list*
128+
* [Python 3.8](https://www.python.org/)
125129

126130
## License
127131

TODO.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# TODO List
2+
3+
* [ ] Add a *"hackban"* command (ban a user by ID from a guild without him being in it)
4+
* [ ] Add a basic slur word filter
5+
* [ ] Add a code of conduct for the repository
6+
* [ ] Add a lock command that will let administrators temporary lock a channel, useful in case of a raid
7+
* [ ] Add an archive command that lets administrators archive a text channel in a text file
8+
* [ ] Add an issue and pull request template for the repository
9+
* [ ] Be able to save data to JSON (blacklist, owners, etc.)
10+
* [ ] Move config to JSON

UPDATES.md

+13
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

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

5+
### Version 2.7
6+
7+
* Added a check for `commands.MissingRequiredArgument` in the error handler
8+
* Added a disclaimer section in the [README](README.md) file
9+
* Added the latency of the bot in the `ping` command
10+
* Created the [TODO list](TODO.md) file
11+
* Fixed some error embeds having success (green) colors
12+
* Removed an unnecessary `self.bot.logout()` statement
13+
* Removed the `dick` command, as I want to keep this template safe for work
14+
* Renamed the names of the arguments in some commands
15+
* The bot now **tries** to send an embed in the private message of the command author for the `invite` and `server` commands, if this was not successful it will be sent in the channel
16+
17+
518
### Version 2.6
619

720
* Added new `dailyfact` command that gives a random fact every day, using cool down

bot.py

+9-1
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.6
6+
Version: 2.7
77
"""
88

99
import os
@@ -134,6 +134,14 @@ async def on_command_error(context, error):
134134
color=config["error"]
135135
)
136136
await context.send(embed=embed)
137+
elif isinstance(error, commands.MissingRequiredArgument):
138+
embed = discord.Embed(
139+
title="Error!",
140+
description=str(error).capitalize(),
141+
# We need to capitalize because the command arguments have no capital letter in the code.
142+
color=config["error"]
143+
)
144+
await context.send(embed=embed)
137145
raise error
138146

139147

cogs/fun.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
""""
2+
Copyright © Krypton 2021 - https://github.com/kkrypt0nn
3+
Description:
4+
This is a template to create your own discord bot in python.
5+
6+
Version: 2.7
7+
"""
8+
19
import asyncio
210
import os
311
import random
@@ -55,18 +63,6 @@ async def dailyfact(self, context):
5563
# We need to reset the cool down since the user didn't got his daily fact.
5664
self.dailyfact.reset_cooldown(context)
5765

58-
@commands.command(name="dick")
59-
async def dick(self, context, member: discord.Member = None):
60-
"""
61-
Get the dick's length of a user or yourself.
62-
"""
63-
if not member:
64-
member = context.author
65-
length = random.randrange(15)
66-
embed = discord.Embed(description=f"8{'=' * length}D", color=config["main_color"])
67-
embed.set_author(name=f"{member.display_name}'s Dick", icon_url=member.avatar_url)
68-
await context.send(embed=embed)
69-
7066
@commands.command(name="rps")
7167
async def rock_paper_scissors(self, context):
7268
choices = {

cogs/general.py

+34-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
""""
2+
Copyright © Krypton 2021 - https://github.com/kkrypt0nn
3+
Description:
4+
This is a template to create your own discord bot in python.
5+
6+
Version: 2.7
7+
"""
8+
19
import json
210
import os
311
import platform
@@ -108,44 +116,51 @@ async def ping(self, context):
108116
Check if the bot is alive.
109117
"""
110118
embed = discord.Embed(
119+
title="🏓 Pong!",
120+
description=f"The bot latency is {round(self.bot.latency * 1000)}ms.",
111121
color=config["success"]
112122
)
113-
embed.add_field(
114-
name="Pong!",
115-
value=":ping_pong:",
116-
inline=True
117-
)
118-
embed.set_footer(
119-
text=f"Pong request by {context.message.author}"
120-
)
121123
await context.send(embed=embed)
122124

123125
@commands.command(name="invite")
124126
async def invite(self, context):
125127
"""
126128
Get the invite link of the bot to be able to invite it.
127129
"""
128-
await context.send("I sent you a private message!")
129-
await context.author.send(
130-
f"Invite me by clicking here: https://discordapp.com/oauth2/authorize?&client_id={config.APPLICATION_ID}&scope=bot&permissions=8")
130+
embed = discord.Embed(
131+
description=f"Invite me by clicking [here](https://discordapp.com/oauth2/authorize?&client_id={config['application_id']}&scope=bot&permissions=470150263).",
132+
color=config['main_color']
133+
)
134+
try:
135+
# To know what permissions to give to your bot, please see here: https://discordapi.com/permissions.html and remember to not give Administrator permissions.
136+
await context.author.send(embed=embed)
137+
await context.send("I sent you a private message!")
138+
except discord.Forbidden:
139+
await context.send(embed=embed)
131140

132-
@commands.command(name="server")
141+
@commands.command(name="server", aliases=["support", "supportserver"])
133142
async def server(self, context):
134143
"""
135144
Get the invite link of the discord server of the bot for some support.
136145
"""
137-
await context.send("I sent you a private message!")
138-
await context.author.send("Join my discord server by clicking here: https://discord.gg/HzJ3Gfr")
146+
embed = discord.Embed(
147+
description=f"Join the support server for the bot by clicking [here](https://discord.gg/HzJ3Gfr).",
148+
color=config['main_color']
149+
)
150+
try:
151+
await context.author.send(embed=embed)
152+
await context.send("I sent you a private message!")
153+
except discord.Forbidden:
154+
await context.send(embed=embed)
139155

140156
@commands.command(name="poll")
141-
async def poll(self, context, *args):
157+
async def poll(self, context, *, title):
142158
"""
143159
Create a poll where members can vote.
144160
"""
145-
poll_title = " ".join(args)
146161
embed = discord.Embed(
147162
title="A new poll has been created!",
148-
description=f"{poll_title}",
163+
description=f"{title}",
149164
color=config["success"]
150165
)
151166
embed.set_footer(
@@ -157,7 +172,7 @@ async def poll(self, context, *args):
157172
await embed_message.add_reaction("🤷")
158173

159174
@commands.command(name="8ball")
160-
async def eight_ball(self, context, *args):
175+
async def eight_ball(self, context, *, question):
161176
"""
162177
Ask any question to the bot.
163178
"""
@@ -172,7 +187,7 @@ async def eight_ball(self, context, *args):
172187
color=config["success"]
173188
)
174189
embed.set_footer(
175-
text=f"Question asked by: {context.message.author}"
190+
text=f"The question was: {question}"
176191
)
177192
await context.send(embed=embed)
178193

cogs/help.py

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
""""
2+
Copyright © Krypton 2021 - https://github.com/kkrypt0nn
3+
Description:
4+
This is a template to create your own discord bot in python.
5+
6+
Version: 2.7
7+
"""
8+
19
import os
210
import sys
311

cogs/moderation.py

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
""""
2+
Copyright © Krypton 2021 - https://github.com/kkrypt0nn
3+
Description:
4+
This is a template to create your own discord bot in python.
5+
6+
Version: 2.7
7+
"""
8+
19
import os
210
import sys
311

@@ -18,7 +26,7 @@ def __init__(self, bot):
1826

1927
@commands.command(name='kick', pass_context=True)
2028
@commands.has_permissions(kick_members=True)
21-
async def kick(self, context, member: discord.Member, *args):
29+
async def kick(self, context, member: discord.Member, *, reason="Not specified"):
2230
"""
2331
Kick a user out of the server.
2432
"""
@@ -31,7 +39,6 @@ async def kick(self, context, member: discord.Member, *args):
3139
await context.send(embed=embed)
3240
else:
3341
try:
34-
reason = " ".join(args)
3542
await member.kick(reason=reason)
3643
embed = discord.Embed(
3744
title="User Kicked!",
@@ -52,38 +59,36 @@ async def kick(self, context, member: discord.Member, *args):
5259
except:
5360
embed = discord.Embed(
5461
title="Error!",
55-
description="An error occurred while trying to kick the user.",
56-
color=config["success"]
62+
description="An error occurred while trying to kick the user. Make sure my role is above the role of the user you want to kick.",
63+
color=config["error"]
5764
)
5865
await context.message.channel.send(embed=embed)
5966

6067
@commands.command(name="nick")
6168
@commands.has_permissions(manage_nicknames=True)
62-
async def nick(self, context, member: discord.Member, *, name: str):
69+
async def nick(self, context, member: discord.Member, *, nickname=None):
6370
"""
6471
Change the nickname of a user on a server.
6572
"""
6673
try:
67-
if name.lower() == "!reset":
68-
name = None
69-
await member.change_nickname(name)
74+
await member.edit(nick=nickname)
7075
embed = discord.Embed(
7176
title="Changed Nickname!",
72-
description=f"**{member}'s** new nickname is **{name}**!",
77+
description=f"**{member}'s** new nickname is **{nickname}**!",
7378
color=config["success"]
7479
)
7580
await context.send(embed=embed)
7681
except:
7782
embed = discord.Embed(
7883
title="Error!",
79-
description="An error occurred while trying to change the nickname of the user.",
80-
color=config["success"]
84+
description="An error occurred while trying to change the nickname of the user. Make sure my role is above the role of the user you want to change the nickname.",
85+
color=config["error"]
8186
)
8287
await context.message.channel.send(embed=embed)
8388

8489
@commands.command(name="ban")
8590
@commands.has_permissions(ban_members=True)
86-
async def ban(self, context, member: discord.Member, *args):
91+
async def ban(self, context, member: discord.Member, *, reason="Not specified"):
8792
"""
8893
Bans a user from the server.
8994
"""
@@ -92,11 +97,10 @@ async def ban(self, context, member: discord.Member, *args):
9297
embed = discord.Embed(
9398
title="Error!",
9499
description="User has Admin permissions.",
95-
color=config["success"]
100+
color=config["error"]
96101
)
97102
await context.send(embed=embed)
98103
else:
99-
reason = " ".join(args)
100104
await member.ban(reason=reason)
101105
embed = discord.Embed(
102106
title="User Banned!",
@@ -112,18 +116,17 @@ async def ban(self, context, member: discord.Member, *args):
112116
except:
113117
embed = discord.Embed(
114118
title="Error!",
115-
description="An error occurred while trying to ban the user.",
116-
color=config["success"]
119+
description="An error occurred while trying to ban the user. Make sure my role is above the role of the user you want to ban.",
120+
color=config["error"]
117121
)
118122
await context.send(embed=embed)
119123

120124
@commands.command(name="warn")
121125
@commands.has_permissions(manage_messages=True)
122-
async def warn(self, context, member: discord.Member, *args):
126+
async def warn(self, context, member: discord.Member, *, reason="Not specified"):
123127
"""
124128
Warns a user in his private messages.
125129
"""
126-
reason = " ".join(args)
127130
embed = discord.Embed(
128131
title="User Warned!",
129132
description=f"**{member}** was warned by **{context.message.author}**!",
@@ -141,29 +144,29 @@ async def warn(self, context, member: discord.Member, *args):
141144

142145
@commands.command(name="purge")
143146
@commands.has_permissions(manage_messages=True, manage_channels=True)
144-
async def purge(self, context, number):
147+
async def purge(self, context, amount):
145148
"""
146149
Delete a number of messages.
147150
"""
148151
try:
149-
number = int(number)
152+
amount = int(amount)
150153
except:
151154
embed = discord.Embed(
152155
title="Error!",
153-
description=f"`{number}` is not a valid number.",
156+
description=f"`{amount}` is not a valid number.",
154157
color=config["error"]
155158
)
156159
await context.send(embed=embed)
157160
return
158-
if number < 1:
161+
if amount < 1:
159162
embed = discord.Embed(
160163
title="Error!",
161-
description=f"`{number}` is not a valid number.",
164+
description=f"`{amount}` is not a valid number.",
162165
color=config["error"]
163166
)
164167
await context.send(embed=embed)
165168
return
166-
purged_messages = await context.message.channel.purge(limit=number)
169+
purged_messages = await context.message.channel.purge(limit=amount)
167170
embed = discord.Embed(
168171
title="Chat Cleared!",
169172
description=f"**{context.message.author}** cleared **{len(purged_messages)}** messages!",

0 commit comments

Comments
 (0)