Skip to content

Instantly share code, notes, and snippets.

@GRAYgoose124
Last active May 15, 2018 01:24
Show Gist options
  • Select an option

  • Save GRAYgoose124/e63dfae7dd8abc3a6c33caa9c32dafe4 to your computer and use it in GitHub Desktop.

Select an option

Save GRAYgoose124/e63dfae7dd8abc3a6c33caa9c32dafe4 to your computer and use it in GitHub Desktop.
import json
import os
import time
from discord.ext import commands
# Configuration setup
config_path = os.path.join(os.getcwd(), 'resources', 'config.json')
if os.path.exists(config_path):
with open(config_path) as f:
config = json.load(f)
else:
config = {'token': "",
'owner_id': "",
'plugins': ["utils", "admin"],
'prefixes': ["mu", ".m", "\N{BUG}"]}
with open(config_path) as f:
json.dump(f, config)
raise FileNotFoundError("Please edit the generated config file.")
# Bot setup
bot = commands.Bot(command_prefix=config['prefixes'])
bot.uptime = time.ctime()
@bot.event
async def on_ready():
loaded = []
for plugin in config['plugins']:
try:
bot.load_extension(f'plugins.{plugin}')
loaded.append(plugin)
except Exception as e:
pass
@bot.event
async def on_message(message):
if message.author.bot:
return
await bot.process_commands(message)
@bot.command()
async def uptime():
bot.say(f'Uptime: {bot.uptime}')
if __name__ == '__main__':
bot.run(config['token'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment