Working plugins architecture

This commit is contained in:
cameron 2024-05-10 04:03:17 -04:00
parent 85b86e5fca
commit 362bef1202
3 changed files with 49 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
bot-env/

38
main.py Normal file
View File

@ -0,0 +1,38 @@
import discord
import glob
import os
import logging
import asyncio
import discord.ext.commands
class DankBot(discord.ext.commands.Bot):
async def load_plugins(self):
plugin_path = os.path.join(os.path.dirname(__file__), 'plugins')
plugin_files = glob.glob(os.path.join(plugin_path, '**', 'plugin.py'), recursive=True)
for plugin_file in plugin_files:
plugin_name = os.path.basename(os.path.dirname(plugin_file))
print(f"Loading plugin {plugin_name}")
await self.load_extension(f'plugins.{plugin_name}.plugin')
async def on_ready(self):
print(f'Logged on as {self.user}!')
await self.load_plugins()
await self.change_presence(activity=discord.Game("with the bots"))
async def on_message(self, message):
print(f'Message from {message.author}: {message.content}')
await self.process_commands(message)
async def main():
intents = discord.Intents.default()
intents.message_content = True
logging.basicConfig(level=logging.INFO)
with open(".token") as token_file:
token = token_file.read()
bot = DankBot(intents=intents, command_prefix='!')
await bot.start(token)
if (__name__ == '__main__'):
asyncio.run(main())

10
plugins/pepe/plugin.py Normal file
View File

@ -0,0 +1,10 @@
from discord.ext import commands
import discord
@commands.command()
async def hello(ctx):
await ctx.send(f'Hello {ctx.author.display_name}.')
async def setup(bot):
print("I am being loaded!")
bot.add_command(hello)