Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Discord Bot doesn't send specific message | discord.py

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading