Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import asyncio
- import disnake
- import sqlite3
- import json
- from disnake.ext import commands
- from server.database import create_db
- class MyBot(Bot):
- def __init__(self, config, conn, *args, **kwargs):
- super().__init__(*args, **kwargs)
- self.config = config
- self.db = conn
- def load_cogs(self):
- paths = ["./commands", "./events", "./tasks"]
- for path in paths:
- print("="*30)
- print(f"Loading: {path[2:len(path)]}")
- print("-"*30)
- for root, dirs, modules in os.walk(path):
- for module in modules:
- if not module.endswith(".py"):
- continue
- path = os.path.join(root, module)
- updated_path = (
- path.replace(".py", "")
- .replace(".", "")
- .replace("/", "")
- .replace("\\", ".")
- )[1:len(path)]
- self.load_extension(updated_path)
- print(f"Loaded: {path}")
- print("-"*30)
- print("="*30)
- async def login(self):
- token = self.config["token"]
- await super().login(token)
- async def main():
- create_db()
- conn = sqlite3.connect("./server/main.db")
- with open("./server/config.json", 'r', encoding="utf-8-sig") as f:
- config = json.load(f)
- intents = disnake.Intents.all()
- bot = commands.InteractionBot(config, conn, intents=intents)
- @bot.event
- async def on_ready():
- print(f"{bot.user.name} is online")
- await bot.login()
- if __name__ == '__main__':
- asyncio.run(main())
Advertisement
Add Comment
Please, Sign In to add comment