问题描述
我目前正在尝试制作反自助机器人"机器人.我想为Discord社区做点好事.因此,我尝试创建一个 on_message
事件,该事件可以检测 Embed
是否包含'selfbot',这将导致该消息被删除并被禁止.
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.
我已经开始制作我的机器人了.但是,我不确定如何读取Embed的内容.
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.
推荐答案
下面将检查消息中嵌入内容的标题,描述,页脚和字段中是否包含某些文本
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))
)
这篇关于嵌入标题或描述中的Discord.py检测消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!