Files
aquabot/cogs/admin.py
CramMK a653476e9c General development process
- new cog commands
- new voice cog
- new requirements.txt
- adjusted readme
- added Dockerfile for faster deployment (still WIP)
- other general things
2020-01-23 15:57:30 +00:00

67 lines
1.6 KiB
Python

"""
Admin commands, that can be used from within the chat:
- load
- unload
- reload
https://discordpy.readthedocs.io/en/latest/ext/commands/cogs.html
https://gist.github.com/EvieePy/d78c061a4798ae81be9825468fe146be
"""
# IMPORTS
import discord
from discord.ext import commands
# COG INIT
class Admin(commands.Cog):
def __init__(self, bot):
self.bot = bot
# COG BODY
@commands.command(name="load", hidden=True)
@commands.is_owner()
async def load(self, ctx, *, cog: str):
"""
Used as 'load cogs.COGNAME'
"""
try:
self.bot.load_extension(cog)
except Exception as e:
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
else:
await ctx.send('**`SUCCESS`**')
@commands.command(name="unload", hidden=True)
@commands.is_owner()
async def unload(self, ctx, *, cog: str):
"""
Used as 'unload cogs.COGNAME'
"""
try:
self.bot.unload_extension(cog)
except Exception as e:
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
else:
await ctx.send('**`SUCCESS`**')
@commands.command(name="reload", hidden=True)
@commands.is_owner()
async def reload(self, ctx, *, cog: str):
"""
Used as 'reload cogs.COGNAME'
"""
try:
self.bot.unload_extension(cog)
self.bot.load_extension(cog)
except Exception as e:
await ctx.send(f'**`ERROR:`** {type(e).__name__} - {e}')
else:
await ctx.send('**`SUCCESS`**')
# COG ENDING
def setup(bot):
bot.add_cog(Admin(bot))