如何在discord.py中提及使用用户ID的用户? [英] How do I mention a user using user's id in discord.py?

查看:33
本文介绍了如何在discord.py中提及使用用户ID的用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用discord.py编写一个简单的bot,所以我从有趣的命令开始,例如只是为了弄清楚api

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
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')

推荐答案

因此,经过几天的尝试和错误,我终于想出了解决方法,希望其他人会从中受益并减轻痛苦.该解决方案最终很容易.

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)

这篇关于如何在discord.py中提及使用用户ID的用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆