0
votes

I have a discord Bot written in python and I have made a command called userinfo. When I type +userinfo into the discord chat nothing happens. I don't get any error messages, but the other commands that the bot has still work.

Here is the command:

@client.command(name="userinfo")
async def userinfo(ctx, member: discord.Member = None):
    if not member:
        member = ctx.author
    created_at = member.created_at.strftime("%Y-%m-%d %H:%M:%S")
    joined_at = member.joined_at.strftime("%Y-%m-%d %H:%M:%S")
    created_format = datetime.datetime.strptime(created_at, "%Y-%m-%d %H:%M:%S")
    joined_format = datetime.datetime.strptime(joined_at, "%Y-%m-%d %H:%M:%S")
    created_unix = int(datetime.datetime.timestamp(created_format))
    joined_unix = int(datetime.datetime.timestamp(joined_format))
    desc = f"""
{member.user} wurde am <t:{created_unix}> erstellt
{member.user} ist am <t:{joined_unix}>, Razo Dawn Town gejoined
"""
    embed = discord.Embed(colour=discord.Colour.random(), title=f"**Userinfo von {member.user_name}:**", description=desc)
    await ctx.send(embed=embed)
1

1 Answers

0
votes

Member object dont have user as attribute instead it has name as attribute which helps to solve this problem. You can refer the below code for more understanding


@client.command(name="userinfo")
async def userinfo(ctx, member: discord.Member = None):
    if not member:
        member = ctx.author
    created_at = member.created_at.strftime("%Y-%m-%d %H:%M:%S")
    joined_at = member.joined_at.strftime("%Y-%m-%d %H:%M:%S")
    created_format = datetime.datetime.strptime(created_at, "%Y-%m-%d %H:%M:%S")
    joined_format = datetime.datetime.strptime(joined_at, "%Y-%m-%d %H:%M:%S")
    created_unix = int(datetime.datetime.timestamp(created_format))
    joined_unix = int(datetime.datetime.timestamp(joined_format))
    desc = f"""
{member.name} wurde am <t:{created_unix}> erstellt
{member.name} ist am <t:{joined_unix}>, Razo Dawn Town gejoined
"""
    embed = discord.Embed(colour=discord.Colour.random(), title=f"**Userinfo von {member.name}:**", description=desc)
    await ctx.send(embed=embed)