Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Setting up the base of the testing bot with cog loading utility
- Loading branch information
1 parent
aa534b1
commit 1c77c31
Showing
4 changed files
with
92 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,16 @@ | ||
from discord.ext.commands import Bot | ||
from os import getenv | ||
|
||
from discord.ext.commands import Bot | ||
|
||
|
||
BOT_TOKEN = getenv("BOT_TOKEN") | ||
|
||
print(BOT_TOKEN) | ||
bot = Bot( | ||
command_prefix="@", | ||
case_insensitive=True, | ||
max_messages=10_000 | ||
) | ||
|
||
bot.load_extension("bot.cogs.cogs") | ||
|
||
bot.run(BOT_TOKEN) |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from discord.ext.commands import Bot, Context, group | ||
|
||
|
||
class Cogs: | ||
"""Cog management cog to load, unload, reload the testing cogs""" | ||
|
||
def __init__(self, bot: Bot): | ||
self.bot = bot | ||
|
||
@group(name='cogs', invoke_without_command=True) | ||
async def cogs_group(self, ctx: Context): | ||
await ctx.send(f"No cog action specified!") | ||
|
||
@cogs_group.command(name='load') | ||
async def load_command(self, ctx: Context, cog: str = ""): | ||
cog = cog.lower() | ||
|
||
if cog: | ||
full_cog = f"bot.cogs.{cog}" | ||
|
||
if full_cog not in self.bot.extensions: | ||
try: | ||
self.bot.load_extension(full_cog) | ||
except ImportError: | ||
await ctx.send(f"ImportError while loading {cog}") | ||
except Exception as e: | ||
await ctx.send(f"{e} while loading {cog}") | ||
else: | ||
await ctx.send(f"Loaded {cog}!") | ||
else: | ||
await ctx.send(f"The cog {cog} was already loaded... Try reloading it!") | ||
else: | ||
await ctx.send(f"You didn't specify a cog to load!") | ||
|
||
@cogs_group.command(name='unload') | ||
async def unload_command(self, ctx: Context, cog: str = ""): | ||
cog = cog.lower() | ||
|
||
if cog: | ||
full_cog = f"bot.cogs.{cog}" | ||
|
||
if full_cog == "bot.cogs.cogs": | ||
await ctx.send(f"Can't unload the cogs cog!") | ||
elif full_cog in self.bot.extensions: | ||
try: | ||
self.bot.unload_extension(full_cog) | ||
except Exception as e: | ||
await ctx.send(f"{e} while unloading {cog}!") | ||
else: | ||
await ctx.send(f"Unloaded {cog}!") | ||
else: | ||
await ctx.send(f"Can't unloaded {cog}, as it wasn't loaded!") | ||
else: | ||
await ctx.send(f"You didn't specify a cog to unload!") | ||
|
||
@cogs_group.command(name='reload') | ||
async def reload_command(self, ctx: Context, cog: str = ""): | ||
cog = cog.lower() | ||
|
||
if cog: | ||
full_cog = f"bot.cogs.{cog}" | ||
|
||
if full_cog == "bot.cogs.cogs": | ||
await ctx.send(f"Can't reload the cogs cog!") | ||
elif full_cog in self.bot.extensions: | ||
try: | ||
self.bot.unload_extension(full_cog) | ||
self.bot.load_extension(full_cog) | ||
except Exception as e: | ||
await ctx.send(f"{e} while reloading {cog}!") | ||
else: | ||
await ctx.send(f"Reloaded {cog}!") | ||
else: | ||
await ctx.send(f"Can't reloaded {cog}, as it wasn't loaded!") | ||
else: | ||
await ctx.send(f"You didn't specify a cog to reload!") | ||
|
||
|
||
def setup(bot): | ||
bot.add_cog(Cogs(bot)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DEV_TEST = 530364497509220363 |