Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. import discord
  2. import mysql.connector
  3. import random
  4. client = discord.Client()
  5.  
  6.  
  7.  
  8.  
  9. mydb = mysql.connector.connect(
  10.     host='localhost',
  11.     user="root",
  12.     passwd="secret",
  13.     database="usercurrency",
  14.     port="2565"
  15. )
  16.  
  17. token = "secret"
  18.  
  19.  
  20. def generateSC():
  21.     random.randint(20, 100)
  22.  
  23.  
  24.  
  25. @client.event
  26. async def on_ready():
  27.     print("Bot is logged in.")
  28.     print(mydb)
  29.  
  30. @client.event
  31. async def on_message(message):
  32.     if message.author.bot:
  33.         return
  34.    
  35.     if message.content.lower() == '?help':
  36.         pass
  37.     elif message.content.lower() == '?addrole':
  38.         pass
  39.     elif message.content.lower() == '?daily':
  40.         sc = generateSC()
  41.         print(message.author.name + "will recieve" + str(sc) + "Sythical Coins")
  42.         cursor = mydb.cursor()
  43.         cursor.execute("SELECT user_sc FROM users WHERE client_id = " + str(message.author.id))
  44.         result = cursor.fetchall()
  45.         print(result)
  46.         if(len(result) == 0):
  47.             print("User is not in db, add them")
  48.             cursor.execute("INSERT INTO users VALUES(" + str(message.author.id) + "," + str(sc) + ")")
  49.             mydb.commit()
  50.             print("Inserted...")
  51.         else:
  52.             pass
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. client.run(token)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement