【问题标题】:How do I mention the author of the command in discord.py?如何在 discord.py 中提及命令的作者?
【发布时间】:2021-04-29 04:33:49
【问题描述】:

我正在尝试使命令也提及编写命令的人,如何将其添加到当前命令中:

import discord
from discord.ext import commands
token = "" #bot token here
client = commands.Bot(command_prefix= "!")
@client.command()
async def ping(ctx):
    await ctx.send('pong')

我已尝试添加此代码:

@client.command()
async def command(ctx):
    author = ctx.message.author

.. 但它在打印作者时对我没有用。

【问题讨论】:

    标签: python discord bots discord.py


    【解决方案1】:

    如果您只是想将其添加到命令中,ctx.author.mention 应该可以完成这项工作

    @client.command()
    async def ping(ctx):
        await ctx.send(f'pong {ctx.author.mention}')
    

    【讨论】:

      猜你喜欢
      • 2021-07-26
      • 2019-02-04
      • 2021-09-05
      • 1970-01-01
      • 2022-12-23
      • 1970-01-01
      • 2019-01-29
      • 2017-10-13
      • 2021-07-20
      相关资源
      最近更新 更多