(不和谐.py)有没有什么方法可以让on\u消息事件查看嵌入的消息而不是普通的消息?

2024-06-01 01:25:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我在试着做一个决定不和谐.pybot,它在每个带有on\ message事件的消息中查找给定的关键字。虽然这对普通文本非常有效,但我无法让它处理我所需要的嵌入式消息。有什么办法吗?你知道吗


Tags: 文本消息messageon事件关键字pybot办法
1条回答
网友
1楼 · 发布于 2024-06-01 01:25:36

message.embeds将获得Embed对象的列表。你可以试试

def check_all_message(check_for, message):
    if check_for in message.content:
        return True
    for e in message.embeds:
        if any(item and check_for in item for item in (e.title, e.footer, e.description)):
            return True
        if e.fields:
            for field in e.fields:
                if check_for in field.name or check_for in field.value:
                    return True
    return False

@bot.event
async def on_message(message):
    if message.author == bot.user:
        return
    if check_all_message("apple", message):
        await bot.send_message(message.channel, 'You said "apple"!')

相关问题 更多 >