簡體   English   中英

discord.py中的命令作者怎么寫?

[英]How do I mention the author of the command in discord.py?

我試圖讓命令也提到編寫命令的人,我如何將它添加到當前命令中:

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

..但它對我沒有用,同時也讓它打印作者。

如果您只是想將其添加到命令中,ctx.author.mention 應該可以完成這項工作

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM