【发布时间】: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。
【问题讨论】:
-
这可能会解决您的问题:stackoverflow.com/questions/61569212/…,如果
response["orders"]是一个列表。
标签: python python-3.x discord discord.py