Reputation:
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)
Upvotes: 0
Views: 2466
Reputation: 191
You can use ctx.author.mention
for mentioning the user. The mention
attribute (documented here) returns a string that you can use in the argument to send
.
Example usage:
@bot.command("hello", help="Learn about this bot")
async def hello(ctx: discord.commands.Context):
await ctx.send(f"Hi {ctx.author.mention}! I'm a bot!")
Upvotes: 0
Reputation: 2398
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)
Upvotes: 1