1

I'm trying to create a multipurpose bot. One of the main functions will be to check username availability against the ubisoft endpoint. However the command doesn't work, as I get no output back. What am I doing wrong here, what am I overlooking?

@bot.command()
async def check(ctx, *, arg):

    headers["Authorization"] = "Basic " + base64.b64encode(bytes(open("external/credentials.txt", "r").readline(), "utf-8")).decode("utf-8")
    r = requests.post("https://public-ubiservices.ubi.com/v3/profiles/sessions", json={"Content-Type":"application/json"}, headers=headers)
    if r.status_code == 200:
        if r.json()["ticket"]:
            token = "Ubi_v1 t=" + r.json()["ticket"]
            headers['Authorization'] = token

    url = f"https://public-ubiservices.ubi.com/v3/profiles?nameOnPlatform={arg}&platformType=uplay"
    req = requests.get(url, headers = {

    'Method':'GET',
    'Authority':'public-ubiservices.ubi.com',
    'referer':'https://lb-prod-acc_ount-pdc.ubisoft.com',
    'Ubi-AppId':'c5393f10-7ac7-4b4f-90fa-21f8f3451a04',
    'Authorization': token,
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36',
    'Ubi-RequestedPlatformType':'uplay'})

    if len(req.json()['profiles']) != 0:
        embedVar = discord.Embed(title="", description=f"{arg} is taken", color=0xb0ccb0)
        embedVar.set_author(name="Gxzs' Slave", url='https://github.com/gxzass', icon_url='https://64.media.tumblr.com/3e33d5bb1e9a74f4bf66d0100a96d2a8/3b23a519a865c5eb-8c/s400x600/fea2d95ff38041dc048644449c8ae9d68b08acb9.jpg')    
        await ctx.send(embed=embedVar)

    else:
        embedVar = discord.Embed(title="", description=f"{arg} is available", color=0xb0ccb0)
        embedVar.set_author(name="Gxzs' Slave", url='https://github.com/gxzass', icon_url='https://64.media.tumblr.com/3e33d5bb1e9a74f4bf66d0100a96d2a8/3b23a519a865c5eb-8c/s400x600/fea2d95ff38041dc048644449c8ae9d68b08acb9.jpg')    
        await ctx.send(embed=embedVar)   

The other functions of the bot are called with the @bot.event on_message like this:

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return

    if message.content.startswith('.help general'):
        embedVar = discord.Embed(title="", description="General commands", color=0xb0ccb0)
        embedVar.set_author(name="Gxzs' Slave", url='https://github.com/gxzass', icon_url='https://64.media.tumblr.com/3e33d5bb1e9a74f4bf66d0100a96d2a8/3b23a519a865c5eb-8c/s400x600/fea2d95ff38041dc048644449c8ae9d68b08acb9.jpg')             
        embedVar.add_field(name='.Coinflip', value="Flips a coin", inline=False)
        embedVar.add_field(name='.Poll {message}', value="Create a poll", inline=False)
        embedVar.add_field(name='.Check {name}', value="Check uplay name availability", inline=False)  
        embedVar.add_field(name='.Help general', value="Shows general commands", inline=False)        
        embedVar.add_field(name='.Help music', value="Shows music commands", inline=False)               
        await message.channel.send(embed=embedVar)

1 Answers1

1

Read the full explanation on the discord.py docs but shortly put, the on_message is overriding the message before the command hander can reach it, this can be fixed by just adding a

await bot.process_commands(message)

to the far end of your on_message event

This makes the on_message ignore any command from the bot so the bot.command() can handle it