I'm trying to create a command for my Discord bot: When someone runs -profile @user, it will display their username and id, and if they don't mention a user, it will show their own username and id. However, when I try to do this, I get this error: 'NoneType' object has no attribute 'display_name'
Here is my code:
@bot.command(name = "profile", help = "View someone's profile")
async def profile(ctx, user: discord.User = None):
colorOne = random.randint(0, 255)
colorTwo = random.randint(0, 255)
colorThree = random.randint(0, 255)
ownProfileEmbed = discord.Embed(
title = str(ctx.message.author.display_name) + "'s profile'", description = "**Username:** " + str(ctx.message.author) + "\n" + "**User ID:** " + str(ctx.message.author.id), color = discord.Colour.from_rgb(colorOne, colorTwo, colorThree))
otherProfileEmbed = discord.Embed(
title = str(user.display_name) + "'s profile", description = "**Username:** " + str(user) + "\n" + "**User ID:** " + str(user.id), color = discord.Colour.from_rgb(colorOne, colorTwo, colorThree))
if (user is None):
await ctx.send(embed = ownProfileEmbed)
else:
await ctx.send(embed = otherProfileEmbed)