Files

67 lines
2.1 KiB
Python
Executable File

# main.py
import discord
from discord.ext import commands
import os
from dotenv import load_dotenv
import threading
import itertools
from npc_memory import NPCMemory
from npc_handler import NPCHandler
from cogs.npc import NPCCog
class MyNewHelp(commands.MinimalHelpCommand):
async def send_pages(self):
destination = self.get_destination()
for page in self.paginator.pages:
emby = discord.Embed(description=page)
await destination.send(embed=emby)
class Client(commands.Bot):
def __init__(self):
super().__init__(
command_prefix=self.iterate_prefix("py"),
strip_after_prefix=True,
case_insensitive=True,
intents=discord.Intents.all(),
help_command=MyNewHelp(),
)
def iterate_prefix(self, prefix):
# Avoid generating all case permutations for long prefixes.
# Provide a small set of common-case variants and rely on
# `case_insensitive=True` for command matching.
variants = [prefix, prefix.lower(), prefix.upper()]
# Preserve order but remove duplicates
seen = set()
prefixes = []
for p in variants:
if p not in seen:
seen.add(p)
prefixes.append(p)
return prefixes
async def setup_hook(self): # overwriting a handler
cogs_folder = f"{os.path.abspath(os.path.dirname(__file__))}/cogs"
for filename in os.listdir(cogs_folder):
if filename.endswith(".py"):
try:
await self.load_extension(f"cogs.{filename[:-3]}")
except Exception as e:
print(f"Failed to load {filename}: {e}")
await self.tree.sync()
print("Loaded cogs")
def main():
load_dotenv()
client = Client()
token = os.getenv("DISCORD_TOKEN") or os.getenv("TOKEN")
if not token:
raise SystemExit("ERROR: Discord token not found. Set DISCORD_TOKEN (or TOKEN) in environment.")
client.run(token)
if __name__ == "__main__":
main()