mekasu0124

Untitled

Dec 28th, 2023
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.74 KB | None | 0 0
  1. import os
  2. import asyncio
  3. import disnake
  4. import sqlite3
  5. import json
  6.  
  7. from disnake.ext import commands
  8. from server.database import create_db
  9.  
  10.  
  11. class MyBot(Bot):
  12.     def __init__(self, config, conn, *args, **kwargs):
  13.         super().__init__(*args, **kwargs)
  14.  
  15.         self.config = config
  16.         self.db = conn
  17.  
  18.     def load_cogs(self):
  19.         paths = ["./commands", "./events", "./tasks"]
  20.  
  21.         for path in paths:
  22.             print("="*30)
  23.             print(f"Loading: {path[2:len(path)]}")
  24.             print("-"*30)
  25.  
  26.             for root, dirs, modules in os.walk(path):
  27.                 for module in modules:
  28.                     if not module.endswith(".py"):
  29.                         continue
  30.  
  31.                     path = os.path.join(root, module)
  32.                     updated_path = (
  33.                         path.replace(".py", "")
  34.                         .replace(".", "")
  35.                         .replace("/", "")
  36.                         .replace("\\", ".")
  37.                     )[1:len(path)]
  38.  
  39.                     self.load_extension(updated_path)
  40.                     print(f"Loaded: {path}")
  41.                     print("-"*30)
  42.             print("="*30)
  43.  
  44.     async def login(self):
  45.         token = self.config["token"]
  46.         await super().login(token)
  47.  
  48.  
  49. async def main():
  50.     create_db()
  51.  
  52.     conn = sqlite3.connect("./server/main.db")
  53.  
  54.     with open("./server/config.json", 'r', encoding="utf-8-sig") as f:
  55.         config = json.load(f)
  56.  
  57.     intents = disnake.Intents.all()
  58.  
  59.     bot = commands.InteractionBot(config, conn, intents=intents)
  60.  
  61.     @bot.event
  62.     async def on_ready():
  63.         print(f"{bot.user.name} is online")
  64.  
  65.     await bot.login()
  66.  
  67. if __name__ == '__main__':
  68.     asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment