5
1
Fork 0
mirror of https://github.com/Anvilcraft/jensmemes synced 2024-11-25 23:42:30 +01:00
jensmemes/Bot/bot.py

39 lines
1.3 KiB
Python
Raw Normal View History

2020-06-26 10:25:39 +02:00
#!/usr/bin/env python3
import discord
from discord.ext import commands, tasks
from config import *
import pymysql
from hashlib import md5
bot = commands.Bot(command_prefix=prefix)
@bot.event #print the username and id to the console and change the game status
async def on_ready():
print('Logged in as')
print(bot.user.name)
print(bot.user.id)
print('------')
@bot.command()
async def register(ctx):
2020-06-26 10:50:14 +02:00
if not ctx.guild.id in allowedDiscordServer:
return
2020-07-11 12:37:19 +02:00
try:
name = str(ctx.author)
token = md5(str(ctx.author.id).encode()).hexdigest()
user = bot.get_user(ctx.author.id)
2020-06-26 10:25:39 +02:00
2020-07-11 12:37:19 +02:00
db = pymysql.connect(sqlServer,sqlUser,sqlPassword,sqlDatabase )
cursor = db.cursor()
cursor.execute("SELECT * FROM token WHERE name=%s AND token=%s", (name, token))
if(len(cursor.fetchall()) == 0):
cursor.execute("INSERT INTO token (name, token, uploadsLast24H) VALUES (%s, %s, 0)", (name, token))
db.commit()
db.close()
2020-06-26 10:25:39 +02:00
2020-07-11 12:37:19 +02:00
await user.send("Your Token for Jensmemes is " + token + "\n You can now use https://jensmemes.tilera.xyz/ !")
except:
ctx.send("Failed to send message, please check if you have enabled PM")
2020-06-26 10:25:39 +02:00
2020-06-26 21:13:22 +02:00
bot.run(token, bot=botAccount)#start the bot with the options in config.py