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

后端 未结 6 651
名媛妹妹
名媛妹妹 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:25

    From a User object, use the attribute User.mention to get a string that represents a mention for the user. To get a user object from their ID, you need Client.get_user_info(id). To get the a user from a username ('ZERO') and discriminator ('#6885') use the utility function discord.utils.get(iterable, **attrs). In context:

    if message.content.startswith('!best'):
        user = discord.utils.get(message.server.members, name = 'ZERO', discriminator = 6885)
        # user = client.get_user_info(id) is used to get User from ID, but OP doesn't need that
        await client.send_message(message.channel, user.mention + ' mentioned')
    

提交回复
热议问题