43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
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))
|
|
logger.info(f"Loading plugin {plugin_name}")
|
|
await self.load_extension(f'plugins.{plugin_name}.plugin')
|
|
|
|
async def on_ready(self):
|
|
logger.info(f'Logged on as {self.user}!')
|
|
logger.info(f'Bot name: {self.user.name}')
|
|
await self.load_plugins()
|
|
await self.change_presence(activity=discord.Game("with the bots"))
|
|
|
|
async def on_message(self, message):
|
|
logger.info(f'Message from {message.author}: {message.content}')
|
|
await self.process_commands(message)
|
|
|
|
async def main():
|
|
intents = discord.Intents.default()
|
|
intents.message_content = True
|
|
intents.members = True
|
|
discord.utils.setup_logging(level=logging.INFO, root=True)
|
|
global logger
|
|
logger = logging.getLogger("bot.main")
|
|
|
|
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())
|