此代码允许将编辑过的消息记录在 Discord 服务器上的另一个频道中,但有时它需要发送 GIF 并将其计为已编辑的消息。即使我认为我告诉它忽略嵌入,我该如何解决?
@commands.Cog.listener()
async def on_message_edit(self, message_before, message_after):
if message_before.author == self.client.user: #Checks to see if the author of the edited message wasn't BenBot.
return
elif message_before.author.bot == True: #Checks to see if the author of the edited messages wasn't a bot
return
if len(message_after.embeds)>1: #Checks to see if the message hasn't been edited with an embed.
return
now = datetime.now() #Grabs the current time
current_time=now.strftime("%H:%M:%S") #Formats the current time into a readable form.
current_date=now.strftime("%d/%m/%Y") #Formats the current date into a readable form.
edit_embed=discord.Embed(title = f"Message Edited", description= f'**User:** <@{message_before.author.id}>\n**Channel:** <#{message_before.channel.id}>\n**Server:** {message_before.guild}\n**Message (Before Edit):** \n{message_before.content}\n**Message (After Edit):** \n{message_after.content}\n\n[Jump to This Message]({message_before.jump_url})', color=0x00ff00)
edit_embed.set_footer(text=f"Message ID: {message_before.id}\nDate: {current_date} • Time: {current_time}")
edit_embed.set_author(name =f"{message_before.author}", icon_url=f"{message_before.author.avatar_url}")
archive_edit=self.client.get_channel(789929258184474675) #Grabs the ID of the Edited Messages Channel where the archive is to be stored.
try:
edit_embed.set_image(url=message_after.attachments[0].proxy_url)
except IndexError:
pass
await archive_edit.send(embed=edit_embed) #Sends the edited message
答案 0 :(得分:2)
是的,我也有这个问题,当我发送链接时,discord 会向该链接添加一个嵌入,这将被视为编辑。但是,内容仍将保持不变。所以我用这个条件修复了它:
if message_before.content == message_after.content:
return
因此,您的活动将如下所示:
@commands.Cog.listener()
async def on_message_edit(self, message_before, message_after):
if message_before.author == self.client.user: # Checks to see if the author of the edited message wasn't BenBot.
return
elif message_before.author.bot == True: # Checks to see if the author of the edited messages wasn't a bot
return
elif message_before.content == message_after.content: # Checks to see if there is an actual edit
return
now = datetime.now() # Grabs the current time
current_time = now.strftime("%H:%M:%S") # Formats the current time into a readable form.
current_date = now.strftime("%d/%m/%Y") # Formats the current date into a readable form.
edit_embed = discord.Embed(title = f"Message Edited", description = f'**User:** <@{message_before.author.id}>\n**Channel:** <#{message_before.channel.id}>\n**Server:** {message_before.guild}\n**Message (Before Edit):** \n{message_before.content}\n**Message (After Edit):** \n{message_after.content}\n\n[Jump to This Message]({message_before.jump_url})', color = 0x00ff00)
edit_embed.set_footer(text = f"Message ID: {message_before.id}\nDate: {current_date} • Time: {current_time}")
edit_embed.set_author(name = f"{message_before.author}", icon_url = f"{message_before.author.avatar_url}")
archive_edit = self.client.get_channel(789929258184474675) # Grabs the ID of the Edited Messages Channel where the archive is to be stored.
try:
edit_embed.set_image(url = message_after.attachments[0].proxy_url)
except IndexError:
pass
await archive_edit.send(embed = edit_embed) #Sends the edited message