Skip to content

Commit 5575d50

Browse files
committed
Template v2.4
* Added some fun commands * Colors are saved in the [config file](config.py) for easier usage * Cogs are now being loaded automatically * Fixed some typos
1 parent 3cbab3d commit 5575d50

11 files changed

+157
-63
lines changed

README.md

+7-8
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,13 @@ To setup the bot I made it as simple as possible. I now created a [config.py](co
4545

4646
Here is an explanation of what everything is:
4747

48-
| Variable | What it is |
49-
| ------------------| ----------------------------------------------------------------------|
50-
| BOT_PREFIX | The prefix(es) of your bot |
51-
| TOKEN | The token of your bot |
52-
| APPLICATION_ID | The application ID of your bot |
53-
| OWNERS | The user ID of all the bot owners |
54-
| BLACKLIST | The user ID of all the users who can't use the bot |
55-
| STARTUP_COGS | The cogs that should be automatically loaded when you start the bot |
48+
| Variable | What it is |
49+
| ----------------------| ----------------------------------------------------------------------|
50+
| YOUR_BOT_PREFIX_HERE | The prefix(es) of your bot |
51+
| YOUR_BOT_TOKEN_HERE | The token of your bot |
52+
| APPLICATION_ID | The application ID of your bot |
53+
| OWNERS | The user ID of all the bot owners |
54+
| BLACKLIST | The user ID of all the users who can't use the bot |
5655

5756
## How to start
5857

UPDATES.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Updates List
22
Here is the list of all the updates that I made on this template.
33

4+
### Version 2.4
5+
* Added some fun commands
6+
* Colors are saved in the [config file](config.py) for easier usage
7+
* Cogs are now being loaded automatically
8+
* Fixed some typos
9+
410
### Version 2.3
511
* Made the kick command actually kick
612
* Added a template cog to create cogs easily
@@ -21,4 +27,4 @@ Here is the list of all the updates that I made on this template.
2127

2228
### Version 1.2
2329
* Added blacklist command
24-
* Removed commands cooldown
30+
* Removed commands cool down

bot.py

+14-14
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.3
6+
Version: 2.4
77
"""
88

99
import discord, asyncio, os, platform, sys
@@ -74,15 +74,15 @@ async def status_task():
7474
bot.remove_command("help")
7575

7676
if __name__ == "__main__":
77-
for extension in config.STARTUP_COGS:
78-
try:
79-
bot.load_extension(extension)
80-
extension = extension.replace("cogs.", "")
81-
print(f"Loaded extension '{extension}'")
82-
except Exception as e:
83-
exception = f"{type(e).__name__}: {e}"
84-
extension = extension.replace("cogs.", "")
85-
print(f"Failed to load extension {extension}\n{exception}")
77+
for file in os.listdir("./cogs"):
78+
if file.endswith(".py"):
79+
extension = file[:-3]
80+
try:
81+
bot.load_extension(f"cogs.{extension}")
82+
print(f"Loaded extension '{extension}'")
83+
except Exception as e:
84+
exception = f"{type(e).__name__}: {e}"
85+
print(f"Failed to load extension {extension}\n{exception}")
8686

8787
# The code in this event is executed every time someone sends a message, with or without the prefix
8888
@bot.event
@@ -100,7 +100,7 @@ async def on_message(message):
100100
embed = discord.Embed(
101101
title="You're blacklisted!",
102102
description="Ask the owner to remove you from the list if you think it's not normal.",
103-
color=0xFF0000
103+
color=config.error
104104
)
105105
await context.send(embed=embed)
106106

@@ -110,16 +110,16 @@ async def on_command_completion(ctx):
110110
fullCommandName = ctx.command.qualified_name
111111
split = fullCommandName.split(" ")
112112
executedCommand = str(split[0])
113-
print(f"Executed {executedCommand} command in {ctx.guild.name} by {ctx.message.author} (ID: {ctx.message.author.id})")
113+
print(f"Executed {executedCommand} command in {ctx.guild.name} (ID: {ctx.message.guild.id}) by {ctx.message.author} (ID: {ctx.message.author.id})")
114114

115115
# The code in this event is executed every time a valid commands catches an error
116116
@bot.event
117117
async def on_command_error(context, error):
118118
if isinstance(error, commands.CommandOnCooldown):
119119
embed = discord.Embed(
120120
title="Error!",
121-
description="This command is on a %.2fs cooldown" % error.retry_after,
122-
color=0xFF0000
121+
description="This command is on a %.2fs cool down" % error.retry_after,
122+
color=config.error
123123
)
124124
await context.send(embed=embed)
125125
raise error

cogs/fun.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import os, sys, discord, random, asyncio
2+
from discord.ext import commands
3+
4+
if not os.path.isfile("config.py"):
5+
sys.exit("'config.py' not found! Please add it and try again.")
6+
else:
7+
import config
8+
9+
class Fun(commands.Cog, name="fun"):
10+
def __init__(self, bot):
11+
self.bot = bot
12+
13+
@commands.command(name="dick")
14+
async def dick(self, context, member : discord.Member = None):
15+
"""
16+
Get the dick's length of a user or yourself.
17+
"""
18+
if not member:
19+
member = context.author
20+
length = random.randrange(15)
21+
embed = discord.Embed(description=f"8{'='*length}D", color=config.main_color)
22+
embed.set_author(name=f"{member.display_name}'s Dick", icon_url=member.avatar_url)
23+
await context.send(embed=embed)
24+
25+
@commands.command(name="rps")
26+
async def rock_paper_scissors(self, context):
27+
choices = {
28+
0 : "rock",
29+
1 : "paper",
30+
2 : "scissors"
31+
}
32+
reactions = {
33+
"🪨" : 0,
34+
"🧻" : 1,
35+
"✂" : 2
36+
}
37+
embed = discord.Embed(title="Please choose", color=config.warning)
38+
embed.set_author(name=context.author.display_name, icon_url=context.author.avatar_url)
39+
choose_message = await context.send(embed=embed)
40+
for emoji in reactions:
41+
await choose_message.add_reaction(emoji)
42+
43+
def check(reaction, user):
44+
return user == context.message.author and str(reaction) in reactions
45+
try:
46+
reaction, user = await self.bot.wait_for("reaction_add", timeout=10, check=check)
47+
48+
user_choice_emote = reaction.emoji
49+
user_choice_index = reactions[user_choice_emote]
50+
51+
bot_choice_emote = random.choice(list(reactions.keys()))
52+
bot_choice_index = reactions[bot_choice_emote]
53+
54+
result_embed = discord.Embed(color=config.success)
55+
result_embed.set_author(name=context.author.display_name, icon_url=context.author.avatar_url)
56+
await choose_message.clear_reactions()
57+
58+
if user_choice_index == bot_choice_index:
59+
result_embed.description = f"**That's a draw!**\nYou've chosen {user_choice_emote} and I've chosen {bot_choice_emote}."
60+
result_embed.colour = config.warning
61+
elif user_choice_index == 0 and bot_choice_index == 2:
62+
result_embed.description = f"**You won!**\nYou've chosen {user_choice_emote} and I've chosen {bot_choice_emote}."
63+
result_embed.colour = config.success
64+
elif user_choice_index == 1 and bot_choice_index == 0:
65+
result_embed.description = f"**You won!**\nYou've chosen {user_choice_emote} and I've chosen {bot_choice_emote}."
66+
result_embed.colour = config.success
67+
elif user_choice_index == 2 and bot_choice_index == 1:
68+
result_embed.description = f"**You won!**\nYou've chosen {user_choice_emote} and I've chosen {bot_choice_emote}."
69+
result_embed.colour = config.success
70+
else:
71+
result_embed.description = f"**I won!**\nYou've chosen {user_choice_emote} and I've chosen {bot_choice_emote}."
72+
result_embed.colour = config.error
73+
await choose_message.add_reaction("🇱")
74+
await choose_message.edit(embed=result_embed)
75+
except asyncio.exceptions.TimeoutError:
76+
await choose_message.clear_reactions()
77+
timeout_embed = discord.Embed(title="Too late", color=config.error)
78+
timeout_embed.set_author(name=context.author.display_name, icon_url=context.author.avatar_url)
79+
await choose_message.edit(embed=timeout_embed)
80+
81+
def setup(bot):
82+
bot.add_cog(Fun(bot))

cogs/general.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ async def info(self, context):
1616
"""
1717
embed = discord.Embed(
1818
description="Used Krypton's template",
19-
color=0x00FF00
19+
color=config.success
2020
)
2121
embed.set_author(
2222
name="Bot Information"
@@ -61,7 +61,7 @@ async def serverinfo(self, context):
6161
embed = discord.Embed(
6262
title="**Server Name:**",
6363
description=f"{server}",
64-
color=0x00FF00
64+
color=config.success
6565
)
6666
embed.set_thumbnail(
6767
url=server.icon_url
@@ -97,7 +97,7 @@ async def ping(self, context):
9797
Check if the bot is alive.
9898
"""
9999
embed = discord.Embed(
100-
color=0x00FF00
100+
color=config.success
101101
)
102102
embed.add_field(
103103
name="Pong!",
@@ -134,7 +134,7 @@ async def poll(self, context, *args):
134134
embed = discord.Embed(
135135
title="A new poll has been created!",
136136
description=f"{poll_title}",
137-
color=0x00FF00
137+
color=config.success
138138
)
139139
embed.set_footer(
140140
text=f"Poll created by: {context.message.author} • React to vote!"
@@ -157,7 +157,7 @@ async def eight_ball(self, context, *args):
157157
embed = discord.Embed(
158158
title="**My Answer:**",
159159
description=f"{answers[random.randint(0, len(answers))]}",
160-
color=0x00FF00
160+
color=config.success
161161
)
162162
embed.set_footer(
163163
text=f"Question asked by: {context.message.author}"
@@ -178,7 +178,7 @@ async def bitcoin(self, context):
178178
embed = discord.Embed(
179179
title=":information_source: Info",
180180
description=f"Bitcoin price is: ${response['bpi']['USD']['rate']}",
181-
color=0x00FF00
181+
color=config.success
182182
)
183183
await context.send(embed=embed)
184184

cogs/help.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ async def help(self, context):
1717
prefix = config.BOT_PREFIX
1818
if not isinstance(prefix, str):
1919
prefix = prefix[0]
20-
embed = discord.Embed(title="Help", description="List of available commands:", color=0x00FF00)
20+
embed = discord.Embed(title="Help", description="List of available commands:", color=config.success)
2121
for i in self.bot.cogs:
2222
cog = self.bot.get_cog(i.lower())
2323
commands = cog.get_commands()

0 commit comments

Comments
 (0)