James
James

Reputation: 87

Removing field value from embed issue

Hi I'm wanting to add a check to a embed field. Currently when it's None it will just leave a name="Steam" value and a empty value="[{result2[0]}](http://steamcommunity.com/profiles/{result2[0]}).

I'm wanting to make a check to see if result2 is in the database - I put an if statement if result2: before the embed field - if it does not return None it will show the embed field.` If result returns a None Type then don't show the embed field.

Not sure if this is possible.

Here is an example and a mockup edited in paint

enter image description here

Here is the code I'm working with:

@commands.group(invoke_without_command=True)
    async def profile(self, ctx, user: discord.Member=None):
        user = user or ctx.author
        db = sqlite3.connect('profiles.sqlite')
        cursor = db.cursor()
        cursor.execute(f"SELECT profile FROM profile WHERE username={user.id}")
        result = cursor.fetchone()
        cursor.execute(f"SELECT steam FROM profile WHERE username={user.id}")
        result2 = cursor.fetchone()
        if result is None:
            await ctx.send(f"{user.display_name}'s bio has not been created yet.")
            return
        else:
            desc = f"**Bio:**\n{(result[0])}"
            embed = discord.Embed(title=f"{user.display_name}'s Profile", description=desc, color=user.colour)
            if result2: #here I add the check before adding the embed field
                embed.add_field(name="Steam", value=f"[{result2[0]}](http://steamcommunity.com/profiles/{result2[0]})")
            await ctx.send(embed=embed)

Help would be appreciated.

Upvotes: 0

Views: 275

Answers (1)

Patrick Haugh
Patrick Haugh

Reputation: 60994

It looks like result2 is a list containing None, or something similar. Let's directly check result2[0] as well as result2

        if result2 and result2[0]:
            embed.add_field(name="Steam", value=f"[{result2[0]}](http://steamcommunity.com/profiles/{result2[0]})")

Upvotes: 1

Related Questions