discord.py embed将列表打印为字符串,而不是单独的条目

2024-10-02 08:14:28 发布

您现在位置:Python中文网/ 问答频道 /正文

My bot Embeddes将与整个列表一起作为一个字符串发布,而不是在同一字段中分成多个条目。我很不明白为什么会这样。感谢您的帮助

代码:

fcfile = open(".env")
envlist = fcfile.readlines()
fcfile.close()

names = envlist[4].lower()
names = names.strip('\n')
namelist = names.split('.')
namelist.remove('')
print('Listing active carriers')
embed = discord.Embed(title='Tracked carriers')
embed.add_field(name = 'Carrier Names', value = namelist)
print('Sent!')

await ctx.send(embed=embed)

What happens

What I want to happen


Tags: 字符串代码列表namesmybot条目embed
1条回答
网友
1楼 · 发布于 2024-10-02 08:14:28

我认为这很有意义,nameslist变量是一个列表。你可以用str.join(list)连接它,所以它是一个字符串

nameslist = '\n'.join(nameslist) # Joining the list with newline as the delimiter
embed.add_field(name="Carrier names", value=nameslist)

相关问题 更多 >

    热门问题