close

How do I mention a user using user’s id in discord.py?

Hello Guys, How are you all? Hope You all Are Fine. Today We Are Going To learn about How do I mention a user using user’s id in discord.py in Python. So Here I am Explain to you all the possible Methods here.

Without wasting your time, Let’s start This Article.

Table of Contents

How do I mention a user using user’s id in discord.py?

  1. How do I mention a user using user's id in discord.py?

    So I finally figured out how to do this after few days of trial and error hoping others would benefit from this and have less pain than I actually had.. The solution was ultimately easy..

  2. mention a user using user's id in discord.py

    So I finally figured out how to do this after few days of trial and error hoping others would benefit from this and have less pain than I actually had.. The solution was ultimately easy..

Method 1

So I finally figured out how to do this after few days of trial and error hoping others would benefit from this and have less pain than I actually had.. The solution was ultimately easy..

  if message.content.startswith('!best'):
        myid = '<@201909896357216256>'
        await client.send_message(message.channel, ' : %s is the best ' % myid)

Method 2

Updated answer for discord.py 1.x – 2.x (2021):

Some of the other solutions are now obsolete since discord.py’s syntaxes has changed and the old versions no longer works.

If you only have the user ID, then it’s:

user_id = "201909896357216256"
await message.channel.send(f"<@{user_id}> is the best")

If you have the user/member object, then it’s:

await message.channel.send(f"{user.mention} is the best")

If you only have the user name and discriminator (the bot and user must share a server and members cache must be toggled on):

user = discord.utils.get(client.users, name="USERNAME", discriminator="1234")
if user is None:
    print("User not found")
else:
    await message.channel.send(f"{user.mention} is the best")

Replace message.channel if you have a ctx when using commands instead of on_message.

Summery

It’s all About this issue. Hope all Methods helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which Method worked for you? Thank You.

Also, Read