问题
I created a super simple .report <person>
command. I have it so it will be sent to a certain channel when someone types it. What I wanted to do is have it display the name of the user who reported the other user. I don't know how to go about doing that. Does anyone know the best way?
@bot.command()
async def report(*, message):
await bot.delete(message)
await bot.send_message(bot.get_channel("479177111030988810"), message)
回答1:
You could do something like this, where you take the context (ctx) and from it get the contents of the message and its author
@bot.command(pass_context=True)
async def report(ctx):
await bot.delete_message(ctx.message)
report = f"\"{ctx.message.content[8:]}\" sent by {ctx.message.author}"
await bot.send_message(bot.get_channel("479177111030988810"), report)
来源:https://stackoverflow.com/questions/51978974/how-to-mention-a-sender-of-a-command-discord-py