gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 13:11:16 26 4
gpt4 key购买 nike

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

最佳答案

如果我们看一下 official Discord documentation对于丰富的嵌入限制,我们可以看到总限制为 6000 个字符。

Additionally, the characters in all title, description, field.name, field.value, footer.text, and author.name fields must not exceed 6000 characters in total. Violating any of these constraints will result in a Bad Request response.


但也有个人限制如下:
+-------------+------------------------+
| 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 |
+-------------+------------------------+
*见 this announcementDiscord Developers server
因此,在许多情况下,您可能需要单独检查和处理所有这些限制。最后,这里是如何检查是否达到了总嵌入限制,这是 不是 检查上面的个别限制。
# 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))

关于python - 如何获得不和谐的长度。嵌入 [DISCORD.PY],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64932316/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com