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}')
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(), allowed_mentions=discord.AllowedMentions(roles=False, users=True, everyone=False), intents=discord. Intents( # kwargs found at https://docs.pycord.dev/en/master/api.html?highlight=discord%20intents#discord.Intents guilds=True, members=True, messages=True, reactions=True, presences=True, message_content=True, )) 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 utils import default from utils.data import Bot, HelpFormat from utils.serverdata import ServerData config = default.get("config.json") token = default.get("token.json") print("Logging in...") intents = discord.Intents.default() intents.reactions = True intents.members = True helper = HelpFormat() bot = Bot(command_prefix=config.prefix, intents=intents, prefix=config.prefix, command_attrs=dict(hidden=True), help_command=helper) bot.server_data = ServerData(bot) for file in os.listdir("cogs"): if file.endswith(".py") and not '__init__' in file: name = file[:-3] bot.load_extension(f"cogs.{name}") bot.run(token.t1 + token.t2)