繁体   English   中英

如何获得不和谐的长度。嵌入 [DISCORD.PY]

[英]How to get the length of a discord.Embed [DISCORD.PY]

我需要一种方法来获得嵌入的确切长度,以便我可以检查它是否超过了限制。 因此,如果它确实超过了限制,它可以拆分为多个消息/嵌入。

如果我们查看有关丰富嵌入限制的官方 Discord 文档,我们可以看到总限制为 6000 个字符。

此外,所有titledescriptionfield.namefield.valuefooter.textauthor.name字段中的字符总数不得超过 6000 个字符。 违反任何这些约束将导致Bad Request响应。

但也有个人限制如下:

+-------------+------------------------+
|    Field    |         Limit          |
+-------------+------------------------+
| title       | 256 characters         |
| description | 4096 characters*       |
| fields      | Up to 25 field objects |
| field.name  | 256 characters         |
| field.value | 1024 characters        |
| footer.text | 2048 characters        |
| author.name | 256 characters         |
+-------------+------------------------+

*在Discord Developers 服务器中查看此公告

因此,在许多情况下,您可能需要单独检查和处理所有这些限制。 最后,这里是如何检查的嵌入限制一直打到,这检查以上个人极限。

# embed would be the discord.Embed instance
fields = [embed.title, embed.description, embed.footer.text, embed.author.name]

fields.extend([field.name for field in embed.fields])
fields.extend([field.value for field in embed.fields])

total = ""
for item in fields:
    # If we str(discord.Embed.Empty) we get 'Embed.Empty', when
    # we just want an empty string...
    total += str(item) if str(item) != 'Embed.Empty' else ''

print(len(total))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM