如何从嵌入的不和谐Web块中获取文本

时间:2018-12-16 11:53:56

标签: python-3.x discord discord.py

这是一笔交易,我在获取某种类型的消息内容时遇到了麻烦(不确定其名称),而且自从我访问互联网以来,无论我怎么看,我似乎都无法弄清楚找不到与此相关的任何信息

Message

使用我当前的代码,我可以完美地检测到普通文本(蓝色文本),但是我似乎无法提取该块中的文本,这些块显示为发布在邮件上的URL的一部分

我当前的代码:

async def on_message(message):
    messagecontent = message.content
    if 'test' in messagecontent:
        await client.send_message(message.channel, 'success')

正如我所说,这适用于消息中的普通文本,而不适用于块内的文本,因此我希望这里的人可以帮助我弄清楚这一点

谢谢

1 个答案:

答案 0 :(得分:2)

您可以使用Message.embeds

它在数组内返回字典,因此对于您的Google示例,它将返回

[{'url': 'https://www.google.com//', 'type': 'link', 'title': 'Google', 'description': "Search the world's information, including webpages, images, videos and more. Google has many special features to help you find exactly what you're looking for."}]

因此,要访问“说明”,您可以执行以下操作

@client.event
async def on_message(message):
    if message.embeds:
        print(message.embeds[0]['description'])