换行符不适用于嵌入式消息中的列表-Discord.py [英] Newline not working with lists in embedded messages - Discord.py

查看:81
本文介绍了换行符不适用于嵌入式消息中的列表-Discord.py的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以换行符作为变量的列表,称为 result

  ['**状态:**启用\ n ** Q:**什么是2 + 2?\ n ** \\ A:** 4 \ n \ n **作者:**UltimateDucc#9121 \ n \ n \ n','**状态:**启用\ n **问题:**埃塞俄比亚在哪里?\ n ** \\答:**非洲\ n \ n **作者:** BigSnacc#2466 \ n \ n \ n'] 

当我通过不和谐将其作为嵌入式消息发送时:

  l_msg = discord.Embed(title = f'Page {list_msg}',描述= str(结果),颜色= discord.Colour.blue())等待message.channel.send(embed = l_msg) 

因此,无论出于何种原因,每个 \ n 都会被忽略.

感谢您的帮助.

解决方案

您需要将单个列表条目转换为字符串,而不仅仅是整个列表的字符串表示形式.这是通过

I have a list with newlines as variable called result

['**Status: **Enabled\n**Q: **What is 2 + 2?\n **\\ A: **4\n\n**Author: **UltimateDucc#9121\n\n\n', '**Status: **Enabled\n**Q: **Where is Ethiopia?\n **\\ A: **Africa\n\n**Author: **BigSnacc#2466\n\n\n']

When I send it as an embedded message through discord:

            l_msg = discord.Embed(
            title =  f'Page {list_msg}',
            description = str(result), 
            colour = discord.Colour.blue()
            )            
            await message.channel.send(embed = l_msg)

It comes out as this with every \n being ignored for whatever reason.

Any help is appreciated.

解决方案

You need to convert the individual list entries into strings as opposed to just a string representation of the entire list. This is done with str.join().

Try changing the description line to:

description=''.join(result),

Result:

这篇关于换行符不适用于嵌入式消息中的列表-Discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆