【问题标题】:How to add list from text file to embed?如何将文本文件中的列表添加到嵌入?
【发布时间】:2018-10-18 11:08:35
【问题描述】:

您好,我正在尝试将 .txt 文件中的一些内容作为列表嵌入到嵌入中,但是在命令 !changelog 上将其显示为列表时遇到问题。

我收到此错误:

raise HTTPException(r, data) discord.errors.HTTPException: BAD REQUEST (status code: 400): Invalid Form Body

这是我目前得到的:

@commands.command(invoke_without_command=True, case_insensitive=True)
@checks.is_channel_mod()
async def changelog(self, ctx):


    changelog = open("changelog.txt").readlines()

    embed = discord.Embed(description=changelog, colour=discord.Color(random.randint(0x000000, 0xFFFFFF)))
    embed.title = "Changelog"
    embed.set_image(url='')
    await ctx.send(embed=embed)

您的帮助将不胜感激。

【问题讨论】:

    标签: discord.py embedding discord.py-rewrite


    【解决方案1】:

    用换行符加入列表:

    embed = discord.Embed(description='\n'.join(changelog), 
                          colour=discord.Color(random.randint(0x000000, 0xFFFFFF))
                          title='Changelog')
    await ctx.send(embed=embed)
    

    或者只使用read 而不是readlines

    with open("changelog.txt") as f:
        changelog = f.read()
    
    embed = discord.Embed(description=changelog, 
                          colour=discord.Color(random.randint(0x000000, 0xFFFFFF))
                          title='Changelog')
    await ctx.send(embed=embed)
    

    【讨论】:

    • 天哪
    猜你喜欢
    • 1970-01-01
    • 2018-07-26
    • 1970-01-01
    • 2020-01-14
    • 1970-01-01
    • 2012-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-06-08
    相关资源
    最近更新 更多