Reputation: 39
I'd like to send on a Discord bot a message embed but text is from another file. I did this way and it doesn't work:
@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)
I have the embed message displaying the directory (/home/plo/rkr/res_wins2).
I modified it to read it before send it to 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)
However, it seems only one result goes out... Here is my txt file:
Roi mouton: 9
tomate: 8
The_Portos: 8
Upvotes: 0
Views: 2090
Reputation: 3
Try putting it in a for-loop:
@bot.command()
async def logs(ctx):
embed: discord.Embed = discord.Embed(
title="title", description="description",
color=discord.Color.red()
)
file = open("file.txt", "r")
for line in file.readlines():
l = line.strip()
loglist.append(l)
embed.add_field(name="⠀", value=" `{0}`".format(l), inline=False)
embed.set_author(name="name")
await ctx.send(embed=embed)
Upvotes: 0
Reputation: 3426
@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)
Upvotes: 0
Reputation: 47
You can check the Documentation Here. It will help. However using Java will be easier with like this:
channel.sendMessage("message").addFile(new File("path/to/file")).queue();
Upvotes: 0