如何在 discord.py 中提及用户?

How do I mention a user in discord.py?(如何在 discord.py 中提及用户?)
本文介绍了如何在 discord.py 中提及用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试使用 discord.py 编写一个简单的机器人,所以我开始使用有趣的命令来熟悉这个库.

I'm trying to code a simple bot using discord.py, so I started with the fun commands to get familiar with the library.

import discord

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 message.channel.send(f"hugs {message.author.mention}")

    if message.content.startswith('!best'):
        user_id = "201909896357216256"
        user_mention = ???  # How to convert user_id into a mention
        await message.channel.send(f'{user_mention} is the best')

推荐答案

所以经过几天的反复试验,我终于想出了如何做到这一点,希望其他人能从中受益,并且比我实际拥有的痛苦更少..解决方案最终很简单..

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 中提及用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

How do I make a list of all members in a discord server using discord.py?(如何使用 discord.py 列出不和谐服务器中的所有成员?)
how to change discord.py bot activity(如何更改 discord.py 机器人活动)
Issues with getting VoiceChannel.members and Guild.members to return a full list(让 VoiceChannel.members 和 Guild.members 返回完整列表的问题)
Add button components to a message (discord.py)(将按钮组件添加到消息(discord.py))
on_message() and @bot.command issue(on_message() 和@bot.command 问题)
How to edit a message in discord.py(如何在 discord.py 中编辑消息)