fixed bot_base_cog and made an example cog
This commit is contained in:
parent
25c616b99b
commit
404244c573
2 changed files with 21 additions and 3 deletions
|
|
@ -6,12 +6,14 @@ import logging
|
|||
class BotBaseCog(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
self.cog_name = __name__
|
||||
self.http_session = self.create_aiohttp_session()
|
||||
self.logger = logging.getLogger("bot")
|
||||
|
||||
def setup(self, name):
|
||||
self.cog_name = name.lower()
|
||||
self.working_dir = f"tmp/{self.cog_name}"
|
||||
self.data_dir = f"data/{self.cog_name}"
|
||||
self.folder_setup()
|
||||
self.http_session = self.create_aiohttp_session()
|
||||
self.logger = logging.getLogger("bot")
|
||||
|
||||
def create_aiohttp_session(self):
|
||||
return aiohttp.ClientSession()
|
||||
|
|
|
|||
16
examples/cog_example.py
Normal file
16
examples/cog_example.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
from discord.ext import commands
|
||||
from cogs.base_cog.bot_base_cog import BotBaseCog
|
||||
|
||||
class Ping(BotBaseCog):
|
||||
|
||||
def __init__(self, bot):
|
||||
super().__init__(bot)
|
||||
self.setup(__class__.__name__)
|
||||
|
||||
@commands.command()
|
||||
async def ping(self, ctx):
|
||||
await ctx.send("pong")
|
||||
self.logger.info(f"Ping command called by {ctx.author.name}")
|
||||
|
||||
async def setup(bot):
|
||||
await bot.add_cog(Ping(bot))
|
||||
Loading…
Add table
Add a link
Reference in a new issue