Reputation: 11
@commands.Cog.listener()
async def on_raw_message_delete(self, payload):
try:
conn.reconnect()
except:
pass
print("deleted")
channel=self.client.get_channel(payload.channel_id)
message=await channel.fetch_message(payload.message_id) #<===========
emb=message.embeds
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id={payload.channel_id} and id={payload.guild_id} and code={mes.fields[1].value}")
conn.commit()
discord.errors.NotFound: 404 Not Found (error code:10008): Unknown message
When I changed the code to this, it showed me the another error
@commands.Cog.listener()
async def on_raw_message_delete(self, payload):
try:
conn.reconnect()
except:
pass
print("deleted")
channel=self.client.get_channel(payload.channel_id)
message=payload.cached_message
emb=message.embeds #<===========
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id={payload.channel_id} and id={payload.guild_id} and code={mes.fields[1].value}")
conn.commit()
AttributeError: 'NoneType' object has no attribute 'embeds'
How I can get a content from embeds?
Upvotes: 0
Views: 115
Reputation: 451
If you want the embed from the message, you can use the on_message_delete
event, since it gives you the message object, like this:
async def on_message_delete(message): # Event that triggers every time a message is deleted
try:
conn.reconnect()
except:
pass
print("Deleted")
emb = message.embeds
for mes in emb:
cursor.execute(f"DELETE FROM suggestions WHERE channel_id={message.channel.id} and id={message.guild.id} and code={mes.fields[1].value}")
conn.commit()
Upvotes: 1