Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
import discord
import sys, traceback
import mysql.connector
from botClient import client, botToken, dbuser, dbpasswd
"""Select the modules to load"""
extensions = ['basicFunctionsFile', 'adminFunctionsFile', 'helpFile', 'gameFunctionsFile',
'apiFunctionsFile', 'imageSearchFunctionsFile',
'musicPlayerFile', 'commandErrorHandlerFile']
"""Attempt connection to the MySQL database"""
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 (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)
"""Load the modules selected above in the extensions"""
if __name__ == '__main__':
for extension in extensions:
try:
client.load_extension(extension)
except Exception as error:
print(f'{extension} cannot be loaded [{error}]')
@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.run(botToken)