DavyJonesStockings
DavyJonesStockings

Reputation: 59

Discord.py bot isn't mentioning users properly

I have a bot using discord.py, and I have a happy birthday command where you can say {prefix} hbd <@user>, ie +hbd @friend. My problem is that when the bot mentions the aforementioned user, the user isn't actually pinged, despite the mention showing up in the embed message. Code:

@bot.command() # NUMBER 5
async def hbd(ctx, user: discord.User):
    target = user
    em = discord.Embed(title=f"Happy Birthday!", description=f"Happy Birthday {target.mention}", color=discord.Color.green())
    em.set_footer(text=f"Wishes from {ctx.author}", icon_url=ctx.author.avatar_url)

    await ctx.channel.send(embed=em)

Result of command: Image of result. In the example, I mentioned myself, as seen in the message I sent. But when the bot tries to mention me, it doesn't highlight, nor does it ping the user (I got the help of my friend to test this). Thank you in advance!

Upvotes: 0

Views: 1078

Answers (2)

UnderGame
UnderGame

Reputation: 11

Have you tried not doing target = user? That might fix it!

@bot.command() # NUMBER 5
async def hbd(ctx, user: discord.User):
    em = discord.Embed(title=f"Happy Birthday!", description=f"Happy Birthday {user.mention}", color=discord.Color.green())
    em.set_footer(text=f"Wishes from {ctx.author}", icon_url=ctx.author.avatar_url)

    await ctx.channel.send(embed=em)

Upvotes: -1

Someguy23
Someguy23

Reputation: 131

Pinging is not possible in embeds, however you can add

@bot.command() # NUMBER 5
async def hbd(ctx, user: discord.User):
    target = user
    em = discord.Embed(title=f"Happy Birthday!", description=f"Happy Birthday {target.mention}", color=discord.Color.green())
    em.set_footer(text=f"Wishes from {ctx.author}", icon_url=ctx.author.avatar_url)

    await ctx.channel.send(f'Happy BIRTHDAY! <@!{target.id}', embed=em)

It pings the user outside the message

Hope this helps in some way or form!

Upvotes: 2

Related Questions