You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.py 如何提及/显示命令触发者的用户名并@该用户?

实现方法

discord.py中可以通过命令上下文ctx的author属性获取触发命令的用户对象,根据你的需求选择对应属性插入到Embed描述中即可:

  • 要实现@提及用户(触发用户通知、高亮显示):使用ctx.author.mention
  • 要仅显示用户名(如Jonathan):使用ctx.author.name
  • 要显示带后缀的完整用户名(如Jonathan#9999):直接使用ctx.author

修改后的代码

@client.command(name='clear')
@commands.has_permissions(manage_messages=True)
async def clear(ctx, amount=5,):
    await ctx.channel.purge(limit=amount)
    # 这里以@提及用户为例,你可以替换成上面提到的其他属性适配需求
    Embed = discord.Embed(title = '✅ Success!', description=f'{ctx.author.mention} cleared {amount} messages!', color = 0x00ff00)
    await ctx.message.channel.send(embed=Embed)

内容的提问来源于stack exchange,提问作者Jonathan1600

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.12 22:09:03