【问题标题】:Discord.py Embed text file, get more resultsDiscord.py 嵌入文本文件,获得更多结果
【发布时间】:2020-08-01 16:33:52
【问题描述】:

我想在 Discord 机器人上发送嵌入的消息,但文本来自另一个文件。我这样做了,但它不起作用:

bot.command()
async def gdc(ctx):
    """Wins GDC"""
    index1 = 0
    file = open("/home/plo/rkr/res_wins2", "r")
    for line in file.readlines():
        line = line.strip()
        index1 += 1
        if index1 == 4: break
    message = line
    embed = discord.Embed()
    embed.description = message
    embed.title = title
    embed.colour = 0xF1C40F
    await ctx.send(embed=embed)

但是,似乎只有一个结果出来...这是我的 txt 文件的一部分:

Roi mouton: 9
tomate: 8
The_Portos: 8

结果如下:

【问题讨论】:

    标签: discord.py


    【解决方案1】:

    您正在更改 for 循环中每个循环的值,因此您必须制作一个行列表

    lines = []
    with open("/home/plo/rkr/res_wins2", "r") as file:  # Use this to open and close the file
        for line in file.readlines():
            line = line.strip()
            lines.append(line)
            index1 += 1
            if index1 == 4: break
    
    embed = discord.Embed()
    embed.description = '\n'.join(lines)
    embed.title = title
    embed.colour = 0xF1C40F
    await ctx.send(embed=embed)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-07
      • 2021-06-17
      • 2021-10-26
      • 2023-01-13
      • 2019-05-12
      • 2020-12-04
      • 1970-01-01
      • 2021-06-13
      相关资源
      最近更新 更多