Discord.py嵌入文本文件

时间:2020-07-31 16:16:43

标签: python discord.py

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

@bot.command()
async def gdc(ctx):
    """Wins GDC"""
    message = '/home/plo/rkr/res_wins2'
    title = "GDC"
    embed = discord.Embed()
    embed.description = message
    embed.title = title
    embed.colour = 0xF1C40F
    await ctx.send(embed=embed)

我有显示目录(/ home / plo / rkr / res_wins2)的嵌入消息。

在将其发送给Embed之前,我已对其进行了修改以使其能够读取:

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

enter image description here

4 个答案:

答案 0 :(得分:1)

邮件是否在.txt文件中?如果是这样,您应该阅读文件并将其传递给文本字符串,以便将其与message匹配。 Here,您可以找到处理文件的文档。

答案 1 :(得分:0)

您可以查看文档Here。 我会帮你的。 但是,使用Java会更容易:

channel.sendMessage("message").addFile(new File("path/to/file")).queue();

答案 2 :(得分:0)

@bot.command()
async def gdc(ctx):
    """Wins GDC"""
    
    with open("/home/plo/rkr/res_wins2", "r") as f:
        scores = f.read().splitlines()
    
    final = '\n'.join(scores[0:3])
    embed=discord.Embed(title="Leader Board", description=final,color = 0xF1C40F)
    
    await ctx.send(embed=embed)

答案 3 :(得分:0)

尝试将其放入 for 循环中:

fatal: could not read Password for 'https://my_repo@dev.azure.com': terminal prompts disabled