How to mention a sender of a command? discord.py

梦想的初衷 提交于 2021-02-05 11:50:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!