Skip to content
Permalink
Browse files
Added MySQL db connector and made some minor updates
  • Loading branch information
stavilam committed Nov 10, 2018
1 parent 64ca399 commit a0ce8434d87dac08e856da88eb7cd6057c5c3d31
Showing 1 changed file with 28 additions and 12 deletions.
40 main.py
@@ -2,14 +2,35 @@ import asyncio
import discord
from discord.ext import commands
import sys, traceback
from botClient import client
from botClient import botToken
import guessFile
import aiohttp
import json
import mysql.connector
from botClient import client, botToken, dbuser, dbpasswd

extensions = ['test', 'basicFunctionsFile', 'adminFunctionsFile', 'helpFile', 'gameFunctionsFile',
'apiFunctionsFile']

try: #try to connect to the MySQL database
mydb= mysql.connector.connect(
host ="localhost",
user = dbuser,
passwd = dbpasswd,
database = "testdatabase"
)
print('Successfully connected to the MySQL database.')
mycursor = mydb.cursor()
# mycursor.execute("SHOW DATABASES")

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})")


extensions = ['test', 'basicFunctionsFile', 'helpFile', 'guessFile'] #Extensions list

@client.event
async def on_ready():
print('-----------------------')
print('Logged in as')
print(client.user.name)
print('CID: ' + str(client.user.id))
@@ -25,24 +46,19 @@ if __name__ == '__main__': #Load extensions from other modules

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

if message.content == 'hai':
await message.channel.send('YES')

await client.process_commands(message) #So that events don't disable commands

@client.event
async def on_member_join(member):
# print(ctx.author.guild.name) testing
await message.channel.send(f'Welcome {member.mention} to {member.guild.name}!')
await client.process_commands(message) #So that events don't disable commands
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 a0ce843

Please sign in to comment.