Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import discord as dsc
- import mysql.connector
- sql = connector.connect(user='API', password='Database1', host='127.0.0.1', database='ddbintegration')
- #Begin SQL function definitions
- async def addCharacter(DiscordUser, BeyondID, CharacterName):
- beyondOwner = await getBeyondNameFromDiscord(DiscordUser)
- addchar = ("insert into characters values""(%s, %s, %s")
- data = (BeyondID, beyondOwner, CharacterName)
- cursor = sql.cursor()
- cursor.execute(addchar,data)
- async def getBeyondNameFromDiscord(DiscordName):
- query = ("select BeyondName from users""where DiscordName=%s")
- data = (DiscordName)
- cursor = sql.cursor()
- cursor.execute(query, data)
- return cursor[0]
- async def getCharacters():
- query = ("select * from characters")
- cursor = sql.cursor()
- cursor.execute(query)
- return cursor
- #End SQL function definitions
- #Begin Discord function definitions
- async def list(message):
- reply = ""
- cursor = await getCharacters()
- for beyondID, BeyondOwner in cursor:
- reply += f'{beyondID}|{BeyondOwner} \n '
- await client.send_message(message.channel, reply)
- client = dsc.Client()
- @client.event
- async def on_ready():
- print("Logged in")
- @client.event
- async def on_message(message):
- if message.content.startswith("!test"):
- await client.send_message(message.channel, "Hello, World! I\'m Trying out Discord.py for our bot. This way, Shauna should also be able to read the code, once she's done with her class.")
- elif message.content.startswith("!uid"):
- await client.send_message(message.channel, message.author)
- elif message.content.startswith("!list"):
- await list(message)
- client.run('NTIwNjg4ODMxMTM4MzY1NDQw.Dwqz1A.73cPDca6srC3Ufc3V9c3Gv2loJI')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement