Skip to content

Commit 2d0f342

Browse files
authored
Merge pull request #70 from shndowbots/patch-1
Add new owner only commands - (un)sync & (re)(un)load
2 parents 70890d6 + c3cfb0a commit 2d0f342

File tree

10 files changed

+241
-52
lines changed

10 files changed

+241
-52
lines changed

UPDATES.md

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

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

5+
### Vesion 5.2 (30 September 2022)
6+
7+
* Added `load`, `reload` and `unload` commands.
8+
* Added `sync` and `unsync` commands.
9+
* Code refactoring and cleanup.
10+
511
### Version 5.1 (12 September 2022)
612

713
* Added the `help` command once again

bot.py

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

99
import asyncio
@@ -13,14 +13,12 @@
1313
import random
1414
import sqlite3
1515
import sys
16-
1716
from contextlib import closing
1817

1918
import discord
2019
from discord import Interaction
21-
from discord.ext import tasks, commands
22-
from discord.ext.commands import Bot
23-
from discord.ext.commands import Context
20+
from discord.ext import commands, tasks
21+
from discord.ext.commands import Bot, Context
2422

2523
import exceptions
2624

@@ -73,7 +71,8 @@
7371
"""
7472
# intents.message_content = True
7573

76-
bot = Bot(command_prefix=commands.when_mentioned_or(config["prefix"]), intents=intents, help_command=None)
74+
bot = Bot(command_prefix=commands.when_mentioned_or(
75+
config["prefix"]), intents=intents, help_command=None)
7776

7877

7978
def init_db():
@@ -97,6 +96,7 @@ def connect_db():
9796
bot.config = config
9897
bot.db = connect_db()
9998

99+
100100
@bot.event
101101
async def on_ready() -> None:
102102
"""
@@ -108,7 +108,6 @@ async def on_ready() -> None:
108108
print(f"Running on: {platform.system()} {platform.release()} ({os.name})")
109109
print("-------------------")
110110
status_task.start()
111-
await bot.tree.sync()
112111

113112

114113
@tasks.loop(minutes=1.0)
@@ -145,7 +144,8 @@ async def on_command_completion(context: Context) -> None:
145144
print(
146145
f"Executed {executed_command} command in {context.guild.name} (ID: {context.guild.id}) by {context.author} (ID: {context.author.id})")
147146
else:
148-
print(f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs")
147+
print(
148+
f"Executed {executed_command} command by {context.author} (ID: {context.author.id}) in DMs")
149149

150150

151151
@bot.event
@@ -222,4 +222,4 @@ async def load_cogs() -> None:
222222

223223
init_db()
224224
asyncio.run(load_cogs())
225-
bot.run(config["token"])
225+
bot.run(config["token"])

cogs/fun.py

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

99
import random
@@ -13,7 +13,6 @@
1313
from discord import app_commands
1414
from discord.ext import commands
1515
from discord.ext.commands import Context
16-
1716
from helpers import checks
1817

1918

@@ -66,7 +65,10 @@ async def callback(self, interaction: discord.Interaction):
6665
bot_choice_index = choices[bot_choice]
6766

6867
result_embed = discord.Embed(color=0x9C84EF)
69-
result_embed.set_author(name=interaction.user.name, icon_url=interaction.user.avatar.url)
68+
result_embed.set_author(
69+
name=interaction.user.name,
70+
icon_url=interaction.user.avatar.url
71+
)
7072

7173
if user_choice_index == bot_choice_index:
7274
result_embed.description = f"**That's a draw!**\nYou've chosen {user_choice} and I've chosen {bot_choice}."
@@ -104,7 +106,7 @@ def __init__(self, bot):
104106
async def randomfact(self, context: Context) -> None:
105107
"""
106108
Get a random fact.
107-
109+
108110
:param context: The hybrid command context.
109111
"""
110112
# This will prevent your bot from stopping everything when doing a web request - see: https://discordpy.readthedocs.io/en/stable/faq.html#how-do-i-make-a-web-request
@@ -132,7 +134,7 @@ async def randomfact(self, context: Context) -> None:
132134
async def coinflip(self, context: Context) -> None:
133135
"""
134136
Make a coin flip, but give your bet before.
135-
137+
136138
:param context: The hybrid command context.
137139
"""
138140
buttons = Choice()
@@ -143,7 +145,6 @@ async def coinflip(self, context: Context) -> None:
143145
message = await context.send(embed=embed, view=buttons)
144146
await buttons.wait() # We wait for the user to click a button.
145147
result = random.choice(["heads", "tails"])
146-
print(buttons.value)
147148
if buttons.value == result:
148149
embed = discord.Embed(
149150
description=f"Correct! You guessed `{buttons.value}` and I flipped the coin to `{result}`.",
@@ -164,7 +165,7 @@ async def coinflip(self, context: Context) -> None:
164165
async def rock_paper_scissors(self, context: Context) -> None:
165166
"""
166167
Play the rock paper scissors game against the bot.
167-
168+
168169
:param context: The hybrid command context.
169170
"""
170171
view = RockPaperScissorsView()

cogs/general.py

+1-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: 5.1
6+
Version: 5.2
77
"""
88

99
import platform

cogs/moderation.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,14 @@
33
Description:
44
This is a template to create your own discord bot in python.
55
6-
Version: 5.1
6+
Version: 5.2
77
"""
88

99
import discord
1010
from discord import app_commands
1111
from discord.ext import commands
1212
from discord.ext.commands import Context
13-
14-
from helpers import checks
15-
from helpers import db_manager
13+
from helpers import checks, db_manager
1614

1715

1816
class Moderation(commands.Cog, name="moderation"):
@@ -112,7 +110,7 @@ async def nick(self, context: Context, user: discord.User, nickname: str = None)
112110
async def ban(self, context: Context, user: discord.User, reason: str = "Not specified") -> None:
113111
"""
114112
Bans a user from the server.
115-
113+
116114
:param context: The hybrid command context.
117115
:param user: The user that should be banned from the server.
118116
:param reason: The reason for the ban. Default is "Not specified".
@@ -176,7 +174,8 @@ async def warning_add(self, context: Context, user: discord.User, reason: str =
176174
:param reason: The reason for the warn. Default is "Not specified".
177175
"""
178176
member = context.guild.get_member(user.id) or await context.guild.fetch_member(user.id)
179-
total = db_manager.add_warn(user.id, context.guild.id, context.author.id, reason)
177+
total = db_manager.add_warn(
178+
user.id, context.guild.id, context.author.id, reason)
180179
embed = discord.Embed(
181180
title="User Warned!",
182181
description=f"**{member}** was warned by **{context.author}**!\nTotal warns for this user: {total}",
@@ -227,13 +226,13 @@ async def warning_add(self, context: Context, user: discord.User, warn_id: int)
227226
async def warning_list(self, context: Context, user: discord.User):
228227
"""
229228
Shows the warnings of a user in the server.
230-
229+
231230
:param context: The hybrid command context.
232231
:param user: The user you want to get the warnings of.
233232
"""
234233
warnings_list = db_manager.get_warnings(user.id, context.guild.id)
235234
embed = discord.Embed(
236-
title = f"Warnings of {user}",
235+
title=f"Warnings of {user}",
237236
color=0x9C84EF
238237
)
239238
description = ""

0 commit comments

Comments
 (0)