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

查看:137
本文介绍了我如何在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天全站免登陆