Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

python - How do I mention the author of the command in discord.py?

I'm trying to make the command also mention the person who wrote the command, how do I add it to the current command:

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')

I have tried to add this code:

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

.. but it hasn't worked for me while making it print the author as well.

question from:https://stackoverflow.com/questions/65883612/how-do-i-mention-the-author-of-the-command-in-discord-py

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you are just looking to add it to a command, ctx.author.mention should do the job

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...