【问题标题】:Py ignoring NewlinesPy忽略换行符
【发布时间】:2021-03-07 16:16:59
【问题描述】:

基本上,python 忽略了字符串中的 \n。

基本上,我使用 request.get 调用 api,然后接收其中包含 \n 的响应,但每当我使用来自 web 的包含 \n 的响应时,它都会忽略它而只是显示它

我这样做是为了一个不和谐的机器人

代码:

@bot.command()
async def genlist(ctx):
        if "BOT ACCESS" in [r.name for r in ctx.message.author.roles]:
            response = json.loads(requests.get(url + f"/api.php?action=orderlist&key=").text)

            if response["status"] == 200:
                orders= str(response["orders"])
                embed=discord.Embed(title="Orders", description="Orders\n" + orders, color=0xcd65f0)
            else:
                embed=discord.Embed(title="Orders", color=0xff0000)
                embed.add_field(name="Unexpected error", value="True", inline=True)
                embed.add_field(name="Message", value= response["message"], inline=True)
                embed.set_footer(text="Error")

如果有人知道原因,请lmk。

【问题讨论】:

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


【解决方案1】:

Discord 会忽略多个 \n,因此要获得双新行,您必须使用 \n\n\u200b 插入 2 个新行和空格。您可以使用BeautifulSoup 库来帮助解析响应。

您可以尝试遍历 \n 并在其后添加 unicode \u200b

【讨论】:

    猜你喜欢
    • 2021-06-17
    • 2017-03-27
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    • 2020-08-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多