from models.user import User from mee6_py_api import API from base import db, config, client import datetime # Runs once bot has connected to discord @client.event async def on_ready(): db.create_tables([User]) time_now = datetime.datetime.utcnow() print(f"{time_now}: {client.user} has connected to Discord!") users = [] for guild in client.guilds: if guild.id == config["discord_server_id"]: print(f"{time_now}: {client.user} has joined {guild.name}!") for member in guild.members: print(member) print(member.display_name) print(member.nick) print(member.joined_at) users.append( User( username=member.name, display_name=member.display_name, discord_id=member.id, joined_date=member.joined_at, ) ) mee6API = API(config["discord_server_id"]) mee6_levels = await mee6API.levels.get_leaderboard_page(0) for user in users: for mee6_user in mee6_levels["players"]: if mee6_user["username"] == user.username: user.level = mee6_user["level"] user.exp = mee6_user["xp"] user.message_count = mee6_user["message_count"] print(user) user.save() client.run(config["discord_token"])