I'm trying to code a simple bot using discord.py, so I started with the fun commands to get familiar with the library.
import discord
client = discord.Client()
@client.event
async def on_message(message):
# we do not want the bot to reply to itself
if message.author == client.user:
return
if message.content.startswith('!hug'):
await message.channel.send(f"hugs {message.author.mention}")
if message.content.startswith('!best'):
user_id = "201909896357216256"
user_mention = ??? # How to convert user_id into a mention
await message.channel.send(f'{user_mention} is the best')
Discord uses a special syntax to embed mentions in a message. For user mentions, it is the user's ID with <@ at the start and > at the end, like this: <@86890631690977280> . If they have a nickname, there will also be a ! after the @ . Role mentions and channel mentions work similarly.
Instead, tapping the user's icon brings up their profile (previously tap and hold), and tapping their username will mention them in chat.
From any text channel, simply type @(The name of the role) , select it, and hit enter. You can also mention roles by ID. This is useful for programmers who write bots for Discord, or create Webhooks, because if the name of the role changes, the mention still works.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With