# disbot.py import yaml import discord from discord.ext import commands # Create empty config variable. Will be filled later. config = "" try: config_file = open("config.yml") except IOError: print("File config.yml not found. Please create one in an empty directory. Documentation here: https://gitlab.nextgamers.eu/weStart/DisBot/wikis/config.yml") exit(0) # Load config_file into variable config config = yaml.load(config_file) # Close config file, content is in variable config. config_file.close() print("Config was found and loaded. Good job :).") if(config['token'] == "TOKEN_HERE"): print("Please set a proper Discord token.") exit(1) print("Now starting the bot with configured token.") # Initialize the bot with prefix and a description from the config. bot = commands.Bot(command_prefix=config['prefix'], description=config['desc']) @bot.event async def on_ready(): """"When the bot is successfully connected to Discord.""" print(f"Logged in as: {bot.user.name}") print(f"UserID: {bot.user.id}") await bot.change_presence(game=discord.Game(name=config['game'])) @bot.command() async def load(extension_name: str): """Loads an extension.""" try: bot.load_extension(extension_name) except (AttributeError, ImportError) as e: await bot.say("```py\n{}: {}\n```".format(type(e).__name__, str(e))) return await bot.say("{} loaded.".format(extension_name)) @bot.command() async def unload(extension_name: str): """Unloads an extension.""" bot.unload_extension(extension_name) await(bot.say("{} unloaded.".format(extension_name))) @bot.command() async def test(): """Just replies - testing the bot.""" await bot.say("confirmed.") bot.run(config['token'])