Skip to content

Instantly share code, notes, and snippets.

@noirscape
Last active December 30, 2017 22:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noirscape/cc8e65c1c42f26af0a9b3780e161817d to your computer and use it in GitHub Desktop.
Save noirscape/cc8e65c1c42f26af0a9b3780e161817d to your computer and use it in GitHub Desktop.
A minimalist discord bot framework
import yaml
from discord.ext import commands
'''A simple bot framework.
Simply configure the options in config.yaml and start the bot with `python3 main.py`
Make sure to run requirements.txt first!
The bot does -not- have any commands by default. You will either need to add them manually or use the included cog loader.
Licensed under the WTFPL (although credit is preferred if you use this as a base)'''
config = yaml.safe_load(open('config.yaml'))
bot = commands.Bot(command_prefix=commands.when_mentioned_or(
config['prefix']),
description='A simple bot framework anyone can use',
pm_help=True)
def load_cog(cog):
'''Try to load a cog and fail gracefully if it errors.'''
try:
bot.load_extension(cog)
except Exception as e:
print('Could not load cog ' + cog)
print(e)
@bot.event
async def on_ready():
print('------------')
print('Logged in as:')
print(bot.user.name)
print(bot.user.id)
print('Using prefix:')
print(config['prefix'])
print('------------')
bot.run(config['token'])
--
token: #Insert the token here
prefix: #Insert the bot prefix here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment