Skip to content
Permalink
Browse files
Updated extensions load list + comments
  • Loading branch information
stavilam committed Nov 28, 2018
1 parent 2184b60 commit 79283263259edc217a7e8edc1b3190ff52ab75b7
Showing 1 changed file with 13 additions and 19 deletions.
32 main.py
@@ -1,15 +1,14 @@
import asyncio
import discord
from discord.ext import commands
import sys, traceback
import aiohttp
import json
import mysql.connector
from botClient import client, botToken, dbuser, dbpasswd

"""Select the modules to load"""
extensions = ['basicFunctionsFile', 'adminFunctionsFile', 'helpFile', 'gameFunctionsFile',
'apiFunctionsFile']
'apiFunctionsFile', 'imageSearchFunctionsFile',
'musicPlayerFile', 'commandErrorHandlerFile']

"""Attempt connection to the MySQL database"""
try: #try to connect to the MySQL database
mydb= mysql.connector.connect(
host ="localhost",
@@ -23,20 +22,24 @@ try: #try to connect to the My

for x in mycursor:
print(x)
except mysql.connector.errors.InterfaceError as error: #if bot can't connect to db (maybe it's offline)
print(f"Can't establish connection to database. Error details: ({error})")

except mysql.connector.errors.InterfaceError as error: #if bot can't connect to db (e.g it's offline)
print(error)


"""Confirms the bot is ready"""
@client.event
async def on_ready():
print('-----------------------')
print('Logged in as')
print(client.user.name)
print('CID: ' + str(client.user.id))
print('-----------------------')
"""Sets the bot status message on Discord"""
text = discord.Game(">comhelp | Waiting for rA9")
await client.change_presence(status=discord.Status.online, activity=text)

if __name__ == '__main__': #Load extensions from other modules
"""Load the modules selected above in the extensions"""
if __name__ == '__main__':
for extension in extensions:
try:
client.load_extension(extension)
@@ -46,19 +49,10 @@ if __name__ == '__main__': #Load extensions from other modules

@client.event
async def on_message(message):
"""So that the bot doesn't reply to itself."""
if message.author.id == client.user.id:
return
await client.process_commands(message) #So that events don't disable commands


@client.event
async def on_member_join(member):
await message.channel.send(f'Welcome {member.mention} to {member.guild.name}!')
await client.process_commands(message) #So that events don't disable commands

@client.command()
async def ctest(ctx):
await ctx.send('I heard you! {}'.format(ctx.author.mention))


client.run(botToken)

0 comments on commit 7928326

Please sign in to comment.