Files
Open-Assistant/discord-bot/bot/config.py
T
2022-12-30 04:12:54 -08:00

38 lines
850 B
Python

# -*- coding: utf-8 -*-
"""Configuration for the bot."""
import logging
from dataclasses import dataclass
from os import getenv
from dotenv import load_dotenv # type: ignore
load_dotenv()
logger = logging.getLogger(__name__)
@dataclass
class Config:
"""Configuration for the bot."""
token: str
declare_global_commands: int
owner_ids: list[int]
prefix: str
@classmethod
def from_env(cls):
token = getenv("TOKEN", None)
if token is None:
logger.error("Invalid token, please set the TOKEN environment variable.")
exit(1)
return cls(
token=token,
declare_global_commands=int(getenv("DECLARE_GLOBAL_COMMANDS", 0)),
owner_ids=[int(x) for x in getenv("OWNER_IDS", "").split(",")],
prefix=getenv("PREFIX", "./"),
)