添加作者用户名@bot.event

时间:2021-07-06 03:32:47

标签: python discord.py

如何在 @bot.event 函数中添加作者用户名?

@bot.event
async def on_message_edit(message_before, message_after):
    username = ctx.author.name
    embed = discord.Embed(title=f"{username}",description="Logs Server", color=discord.Color.purple(), timestamp=datetime.utcnow())
    channel=bot.get_channel(id)
    await channel.send(embed=embed)

1 个答案:

答案 0 :(得分:1)

你的问题有点令人困惑,但我想我明白你的意思。

因为您在 on_message_edit 内部工作,message_beforemessage_after 都是 Entities 对象。你可以试试这样的:

discord.Message

您最初拥有的 ctx ("username = ctx.author.name") 将不会被定义。这是因为我们通常只有命令内部的上下文,而这不是。