Discord.py Detect message in Embed Title or Description

旧时模样 提交于 2021-01-29 08:13:02

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!