[英]How to get the length of a discord.Embed [DISCORD.PY]
我需要一种方法来获得嵌入的确切长度,以便我可以检查它是否超过了限制。 因此,如果它确实超过了限制,它可以拆分为多个消息/嵌入。
如果我们查看有关丰富嵌入限制的官方 Discord 文档,我们可以看到总限制为 6000 个字符。
此外,所有
title
、description
、field.name
、field.value
、footer.text
和author.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.