Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用css代码格式打印彩色文本_Python_Discord.py - Fatal编程技术网

Python 使用css代码格式打印彩色文本

Python 使用css代码格式打印彩色文本,python,discord.py,Python,Discord.py,嗨,我有一个简单的机器人,它接受命令: @bot.command(name='repeat', help='help me to understand bots') async def test(ctx, *lines): print("repeating") coloured_lines=[] for line in lines: coloured_lines.append("```css \n"+ line +

嗨,我有一个简单的机器人,它接受命令:

@bot.command(name='repeat', help='help me to understand bots')
async def test(ctx, *lines):
    print("repeating")
    coloured_lines=[]
    for line in lines:
        coloured_lines.append("```css \n"+ line + "```")
    await asyncio.gather(*[ctx.send(line) for line in coloured_lines])
您可以向其写入一个命令,如$repeat“green text is cool”,并应获得如下输出:


相反,你得到了。我的直觉是,这是因为“字符”发生了一些事情-尽管我不确定是什么,或者如何修复它。

colored\u line.append(“``css\n”+line+“``````”)
在标记空间的计数中,而
css
不是有效的文件格式,而
css
是<代码>彩色线。追加(“``css\n”+线+“```”)


奇怪的是,如果您删除了将行放入css代码区域的代码行,然后让机器人重复css区域中已经存在的内容,结果会很好。在标记文本[
代码块
]中,每个空格都会被计数!
代码块
文本的第一行表示它是什么类型的文本!所以,您必须只键入“css”,结尾没有任何空格!