def main(): config = default.get_from_env("CONFIG") if config is None: exit(3) print("機器人登入中 ...") bot = Bot(command_prefix=config.prefix, prefix=config.prefix, command_attrs=dict(hidden=True), help_command=HelpFormat()) for file in os.listdir("cogs"): if file.endswith(".py"): name = file[:-3] bot.load_extension(f"cogs.{name}") token = os.environ.get("TOKEN") if token is None: exit(2) bot.run(token)
import os import discord from utils import default from utils.data import Bot, HelpFormat config = default.config() print("Logging in...") bot = Bot( command_prefix=config["prefix"], prefix=config["prefix"], owner_ids=config["owners"], command_attrs=dict(hidden=True), help_command=HelpFormat(), intents=discord.Intents( # kwargs found at https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#discord.Intents guilds=True, members=True, messages=True, reactions=True, presences=True ) ) for file in os.listdir("cogs"): if file.endswith(".py"): name = file[:-3] bot.load_extension(f"cogs.{name}") try: bot.run(config["token"]) except Exception as e: print(f'Error when logging in: {e}')
from utils import default from utils.data import Bot, HelpFormat config = default.get("config.json") print("Logging in...") bot = Bot( command_prefix=config.prefix, prefix=config.prefix, owner_ids=config.owners, command_attrs=dict(hidden=True), help_command=HelpFormat(), intents=discord. Intents( # kwargs found at https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#discord.Intents guilds=True, members=True, messages=True, reactions=True, presences=True)) for file in os.listdir("cogs"): if file.endswith(".py"): name = file[:-3] bot.load_extension(f"cogs.{name}") bot.load_extension("jishaku") try: bot.run(config.token) except Exception as e: print(f'Error when logging in: {e}')
config_json = False try: import config except ImportError: if os.environ.get('config'): raise ImportError("Can not load config") import json config = json.dumps(os.environ.get('config')) config_json = True print("Logging in...") bot = Bot( command_prefix=config.PREFIX, prefix=config.PREFIX, owner_ids=config.OWNERS, command_attrs=dict(hidden=True), help_command=HelpFormat(), intents=discord.Intents( # kwargs found at https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#discord.Intents guilds=True, members=True, messages=True, reactions=True, presences=True ) ) for file in os.listdir("cogs"): if file.endswith(".py"): bot.load_extension(f"cogs.{file[:-3]}") try: bot.run(config['token'] if config_json else config.TOKEN) except Exception as e: print(f'Error when logging in:\n{e}')
import os import discord from dotenv import load_dotenv from utils.data import Bot, HelpFormat load_dotenv() TOKEN = os.getenv("DISCORD_TOKEN") intents = discord.Intents.default() intents.members = True bot = Bot(command_prefix=os.getenv("PREFIX"), prefix=os.getenv("PREFIX"), command_attrs=dict(hidden=True), help_command=HelpFormat(), intents=intents) for file in os.listdir("commands"): if file.endswith(".py"): name = file[:-3] bot.load_extension(f"commands.{name}") try: bot.run(TOKEN) except Exception as e: print(f'Error when logging in: {e}')