discorddiscord.py

Trying to get my discord bot to log a command and who has used it


Here is my code.

@bot.command()
async def ping(ctx)
    embed = discord.Embed(title = "Bot Latency", description=f"Latency: {round(bot.latency * 1000)}ms")
    await ctx.reply(embed = embed)
    channel = bot.get_channel(1376165325950812222)
    embed = discord.Embed(title="Bot Command Log", description="The ~ping command was just executed by {message.author}", color=discord.Color.from_rgb(210, 4, 45))
    await channel.send(embed = embed)

The output for this is " Bot Command Log, The ~ping command was just executed by {message.author}"

However I want it to actually @ the member who executed the command and not just put {message.author}

if you have any suggestions let me know please.


Solution

  • Use the Member.mention attribute:

    @bot.command()
    async def ping(ctx)
        embed = discord.Embed(title = "Bot Latency", description=f"Latency: {round(bot.latency * 1000)}ms")
        await ctx.reply(embed = embed)
        channel = bot.get_channel(1376165325950812222)
        embed = discord.Embed(
            title="Bot Command Log",
            description=f"The ~ping command was just executed by {ctx.author.mention}",
            color=discord.Color.from_rgb(210, 4, 45)
        )
        await channel.send(embed = embed)