From 0ff86483520b1fde7c80623bea37d41649c2f1b0 Mon Sep 17 00:00:00 2001 From: TheTechRobo <52163910+TheTechRobo@users.noreply.github.com> Date: Sat, 5 Jun 2021 11:12:30 -0400 Subject: [PATCH] add first command :D --- Token.example.py | 1 + bot.py | 39 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/Token.example.py b/Token.example.py index d9d293a..d769d3f 100644 --- a/Token.example.py +++ b/Token.example.py @@ -5,3 +5,4 @@ HYPIXEL_API_KEY = "Hypixel API key goes here (run /api new ingame to get it)" DISCORD_API_KEY = "Discord bot token goes here" +PREFIX = ("$") diff --git a/bot.py b/bot.py index db72147..2c54b8e 100644 --- a/bot.py +++ b/bot.py @@ -1,6 +1,41 @@ -import discord +# {{{ Imports +import discord, requests, json +from discord.ext import commands +# }}} +# {{{ Get token try: - from Token import HYPIXEL_API_KEY, DISCORD_API_KEY + from Token import HYPIXEL_API_KEY, DISCORD_API_KEY, PREFIX except ImportError: print("\tFATAL!\tCould not load Token.py file. Please change the Token.example.py to your liking and make sure that it is valid Python syntax") raise +# }}} +# {{{ Setup bot +bot = commands.Bot(command_prefix=PREFIX) +@bot.event +async def on_ready(): + print("Ready for action Rider sir!") + print("PAW PATROL! PAW PATROL! WE'LL BE THERE ON THE DOUBLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE") +# }}} +# {{{ pre-gettext wrapper +def _(string): + return string +# }}} +# {{{ Commands +def getuuid(username): + req = requests.get(f"https://api.mojang.com/users/profiles/minecraft/{username}").text + req = json.loads(req) + return req['id'] +@bot.command(name="uuid") +async def uuid(ctx, username=None): #TODO: instead of doingusername=None, add an error handler if this doesnt get fulfilled + """ + Gets the UUID of a player. based on their username. + """ + if username is None: + await ctx.send(_("Error: you must specify player name")) + return + req = getuuid(username) + await ctx.send(f"Player UUID: {req}") +# }}} +# {{{ Run bot +bot.run(DISCORD_API_KEY) +# }}}