Reputation: 23
I'm trying to make a userinfo command, the command works but only without mentions "grabs my info but doesn't work when i mention someone". The command gives me this when i mention someone to see their info
Command raised an exception: AttributeError: 'ClientUser' object has no attribute 'joined_at'
Here's the code
@bot.command()
async def userinfo(ctx, *, user: discord.User = None): # b'\xfc'
if user is None:
user = ctx.author
date_format = "%a, %d %b %Y %I:%M %p"
embed = discord.Embed(color=0xdfa3ff, description=user.mention)
embed.set_author(name=str(user), icon_url=user.avatar_url)
embed.set_thumbnail(url=user.avatar_url)
embed.add_field(name="Joined", value=user.joined_at.strftime(date_format))
members = sorted(ctx.guild.members, key=lambda m: m.joined_at)
embed.add_field(name="Join position", value=str(members.index(user)+1))
embed.add_field(name="Registered", value=user.created_at.strftime(date_format))
if len(user.roles) > 1:
role_string = ' '.join([r.mention for r in user.roles][1:])
embed.add_field(name="Roles [{}]".format(len(user.roles)-1), value=role_string, inline=False)
perm_string = ', '.join([str(p[0]).replace("_", " ").title() for p in user.guild_permissions if p[1]])
embed.add_field(name="Guild permissions", value=perm_string, inline=False)
embed.set_footer(text='ID: ' + str(user.id))
return await ctx.send(embed=embed)
Upvotes: 2
Views: 15144
Reputation: 1
Well you are using is
user = ctx.author
what you should use is
async def userinfo(ctx, *, user:discord.Member = None):
.
.
.
Upvotes: 0
Reputation: 229
discord.User
has no joined_at
variable.
Use this instead:
@bot.command()
async def userinfo(ctx, *, user: discord.Member = None):
...
I also recommend you to check if the command isn't executed in a private chat otherwise it will raise an error.
if isinstance(ctx.channel, discord.DMChannel):
return
Upvotes: 1