Skip to content
Advertisement

How to tag a user using the discord.Member argument?

I have a discord bot with the command !sad. On execution the bot should reply with a random string from sad_list.

JavaScript

I want the option to have the bot tag someone if you execute the command with the user: discord.Member argument.

Preferred output:

JavaScript

as opposed to only

JavaScript

The following has already been tried:

JavaScript

However this simply writes:

JavaScript

As opposed to actually mentioning them

Advertisement

Answer

Use user.mention to mention users

await ctx.send(f"{user.mention} {sad_list[randint(0, len(sad_list))]} <3")

https://discordpy.readthedocs.io/en/master/api.html?highlight=user%20mention#discord.User.mention

For future references, you could also mention users like this: <@!user_id>, replace user_id with the actual ID of the user. You can use this in cases where user.mention is not practical.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement