问题
I am currently trying to make an 'Anti Selfbot' Bot. I would like to do something good for the Discord Community. Therefore, I have tried to make an on_message
event that can detect if an Embed
contains 'selfbot', which would cause the message to get deleted and for the user to be banned.
I have already begun making my bot. However, I am not sure how to read the content of an Embed.
if 'selfbot' in message.content:
# do some stuff here
So, basically, the only problem I am having at the moment would be reading the embed title or description content.
回答1:
The below checks the title, description, footer, and fields of the embeds in a message for some text
from discord import Embed
def message_contains(message, text):
return text in message.content or any(embed_contains(embed, text) for embed in message.embeds)
def embed_contains(embed, text):
return (text in embed.title
or text in embed.description
or (embed.footer is not Embed.Empty and text in embed.footer.text)
or (embed.fields is not Embed.Empty and any(text in field.name or text in field.value for field in embed.fields))
)
来源:https://stackoverflow.com/questions/64759272/discord-py-detect-message-in-embed-title-or-description