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

后端 未结 6 665
名媛妹妹
名媛妹妹 2020-12-20 13:36

I\'m trying to code a simple bot using discord.py so i started with the fun commands like just to get the hang of the api

import discord
import asyncio
clien         


        
6条回答
  •  长情又很酷
    2020-12-20 14:14

    To mention an user and have their username to display (not their id), you'll need to add a ! to the accepted self-answer.

    await client.send_message(message, '<@!20190989635716256>, hi!')
    

    When you only have the id and not the Member or User object, I'd recommend against using Peter G's answer where they used get() or get_user_info(id) to actually fetch the User/Member object first. These operations are very time consuming and not needed since .mention only return this very string.

提交回复
热议问题