Initial: Add load commands and developer cog
The commands `load`, `unload`, `reload` were added in the main `bot.py` file. With these one can dynamically load extensions like discord cogs. The cog `developer` has some test commands and listeners. It also has a command to shut down the bot (and therefore the python program).
This commit is contained in:
parent
49a407a29d
commit
91f96ce246
22
src/bot.py
22
src/bot.py
|
@ -24,5 +24,27 @@ if TOKEN is None:
|
||||||
|
|
||||||
bot = commands.Bot(command_prefix=commands.when_mentioned_or('$b '))
|
bot = commands.Bot(command_prefix=commands.when_mentioned_or('$b '))
|
||||||
|
|
||||||
|
default_extensions = ['developer']
|
||||||
|
|
||||||
|
for extension in default_extensions:
|
||||||
|
bot.load_extension(f'cogs.{extension}')
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def load(ctx, extension):
|
||||||
|
bot.load_extension(f'cogs.{extension}')
|
||||||
|
print(f'cogs.{extension} loaded')
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def unload(ctx, extension):
|
||||||
|
bot.unload_extension(f'cogs.{extension}')
|
||||||
|
print(f'cogs.{extension} unloaded')
|
||||||
|
|
||||||
|
@bot.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def reload(ctx, extension):
|
||||||
|
bot.reload_extension(f'cogs.{extension}')
|
||||||
|
print(f'cogs.{extension} reloaded')
|
||||||
|
|
||||||
bot.run(TOKEN)
|
bot.run(TOKEN)
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
|
||||||
|
class Developer(commands.Cog):
|
||||||
|
"""This class is intended only for the developer, mainly for testing purposes"""
|
||||||
|
|
||||||
|
def __init__(self, bot):
|
||||||
|
self.bot = bot
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_ready(self):
|
||||||
|
await self.bot.change_presence(status=discord.Status.online, activity=discord.Game('$b help'))
|
||||||
|
print('We have logged in as {0.user}'.format(self.bot))
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
async def hello(self, ctx):
|
||||||
|
await ctx.send(f"Hello {ctx.message.author.name} :wave:")
|
||||||
|
|
||||||
|
@commands.command()
|
||||||
|
@commands.is_owner()
|
||||||
|
async def logout(self, ctx):
|
||||||
|
"""Shut down the bot"""
|
||||||
|
await self.bot.logout()
|
||||||
|
|
||||||
|
def setup(bot):
|
||||||
|
bot.add_cog(Developer(bot))
|
Loading…
Reference in New Issue