python - Discord.py 记录删除和编辑的消息
问题描述
我正在为我的服务器制作一个服务器机器人,我想记录所有消息删除和编辑。它将登录到一个日志通道供工作人员查看。在日志频道中,我想让消息显示删除的内容或消息编辑之前的内容以及消息编辑之后的内容。我将如何让机器人显示已删除或已编辑的消息?
@client.event()
async def on_message_delete(ctx):
embed=discord.Embed(title="{} deleted a message".format(member.name), description="", color="Blue")
embed.add_field(name="What the message was goes here" ,value="", inline=True)
channel=client.get_channel(channel_id)
await channel.send(channel, embed=embed)
解决方案
您可以在使用时使用on_message_delete和on_message_edit,然后您应该给函数消息而不是 ctx。
@client.event()
async def on_message_delete(message):
embed=discord.Embed(title="{} deleted a message".format(message.member.name),
description="", color="Blue")
embed.add_field(name= message.content ,value="This is the message that he has
deleted",
inline=True)
channel=client.get_channel(channel_id)
await channel.send(channel, embed=embed)
@client.event()
async def on_message_edit(message_before, message_after):
embed=discord.Embed(title="{} edited a
message".format(message_before.member.name),
description="", color="Blue")
embed.add_field(name= message_before.content ,value="This is the message before
any edit",
inline=True)
embed.add_field(name= message_after.content ,value="This is the message after the
edit",
inline=True)
channel=client.get_channel(channel_id)
await channel.send(channel, embed=embed)
推荐阅读
- python-3.x - 试图找出我的代码有什么问题
- jenkins - 如何在多模块项目中创建魅力报告
- javascript - Jquery检查是否是对象数组中的最后一个负数
- angular - 如何在 Ionic 中本地化 PWA 相机字符串?
- vue.js - VueJs 重命名属性 doesn't rename them in
- excel - 为什么我在尝试执行时间戳用户定义函数时遇到运行时错误(范围)
- angular-routing - Browser refresh button not working with Angular routing
- package - Issues with creating a tcl package in same directory as other source tcl files
- c# - HTTP get Status code 404 when trying to a .Net project in Ubuntu 20.04
- java - Spring boot login page issue - webpage not found error