我如何在discord.py中提及使用用户ID的用户

发布于 2021-01-29 14:58:34

我正在尝试使用discord.py编写一个简单的机器人,所以我从有趣的命令开始,例如只是为了获得api的优势。

import discord
import asyncio
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 client.send_message(message.channel, "hugs {0.author.mention}".format(message))

    # Greetings
    if message.content.startswith('hello'):
        msg = 'Hello {0.author.mention}'.format(message)
        await client.send_message(message.channel, msg)

    # say (id) is the best
    # This is where I am lost. how to mention someone's name or id ?
    if message.content.startswith('!best'):
        mid = User.id('ZERO#6885').format(message)
        await client.send_message(message.channel, '{mid} mentioned')
关注者
0
被浏览
92
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    因此,我经过几天的反复试验终于弄清楚了如何做到这一点,希望其他人可以从中受益,并且比我实际承受的痛苦更少。解决方案最终很容易。

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


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看