【问题标题】:Discord.py - auto-chunking text when sending large messages?Discord.py - 发送大消息时自动分块文本?
【发布时间】:2021-09-17 19:28:52
【问题描述】:

我想发送一个大字符串:

my_text = "...greater.than.4096.chars..."
embed = discord.Embed(title='Hello World')
embed.description = my_text
await ctx.send(embed=embed)

但是我得到这个错误: In embed.description: Must be 4096 or fewer in length.

discord.py 有没有办法自动将字符串拆分成多个块发送?

In discord.js, they have a way to do so like this:

.send(data, { split: true })

discord.py 有类似的东西吗?还是我必须自己编写解决方案?

【问题讨论】:

    标签: python-3.x discord.py


    【解决方案1】:

    据我所知,discord.py 中没有内置方法。但是您当然可以手动拆分它。这样的东西应该有用吗?

    from math import ceil
    
    for i in range(ceil(len(my_text) / 4096)):
        embed = discord.Embed(title='Hello World')
        embed.description = (my_text[(4096*i):(4096*(i+1))])
        await ctx.send(embed=embed)
    

    【讨论】:

      猜你喜欢
      • 2021-05-02
      • 2021-07-08
      • 1970-01-01
      • 2020-11-10
      • 2020-10-31
      • 2017-08-15
      • 2021-07-18
      • 2021-10-15
      • 1970-01-01
      相关资源
      最近更新 更多