【问题标题】:How to get the length of a discord.Embed [DISCORD.PY]如何获得不和谐的长度。嵌入 [DISCORD.PY]
【发布时间】:2021-03-04 00:53:39
【问题描述】:

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

【问题讨论】:

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


    【解决方案1】:

    如果我们查看 official Discord documentation 的丰富嵌入限制,我们可以看到总限制为 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         |
    +-------------+------------------------+
    

    *见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))
    

    【讨论】:

      猜你喜欢
      • 2021-02-26
      • 2020-01-22
      • 2022-01-14
      • 1970-01-01
      • 2021-11-09
      • 1970-01-01
      • 2021-12-26
      • 2022-10-23
      • 1970-01-01
      相关资源
      最近更新 更多