So i have a discord bot (using python) that connect to a sqlite database, and i want to show the data using embed. The data is containing my daily anime schedule.
Here’s the code :
JavaScript
x
33
33
1
@commands.command(aliases=['Schedule'])
2
async def schedule(self, ctx, day = None):
3
if (day==None):
4
conn = sqlite3.connect('./cogs/animelist.db')
5
cursor1 = conn.execute("SELECT name, status_eps from Animelist where day = 'monday'")
6
cursor2 = conn.execute("SELECT name, status_eps from Animelist where day = 'tuesday'")
7
cursor3 = conn.execute("SELECT name, status_eps from Animelist where day = 'wednesday'")
8
cursor4 = conn.execute("SELECT name, status_eps from Animelist where day = 'thursday'")
9
cursor5 = conn.execute("SELECT name, status_eps from Animelist where day = 'friday'")
10
cursor6 = conn.execute("SELECT name, status_eps from Animelist where day = 'saturday'")
11
cursor7 = conn.execute("SELECT name, status_eps from Animelist where day = 'sunday'")
12
13
embed = discord.Embed(
14
title=f'Anime Schedule:',
15
colour=discord.Color.blue())
16
17
for row in cursor1:
18
embed.add_field(name=f'Monday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
19
for row in cursor2:
20
embed.add_field(name=f'Tuesday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
21
for row in cursor3:
22
embed.add_field(name=f'Wednesday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
23
for row in cursor4:
24
embed.add_field(name=f'Thursday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
25
for row in cursor5:
26
embed.add_field(name=f'Friday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
27
for row in cursor6:
28
embed.add_field(name=f'Saturday', value=f'{row[0]} (Eps : {row[1]})', inline=False)
29
for row in cursor7:
30
embed.add_field(name=f'Sunday',value=f'{row[0]} (Eps : {row[1]})',inline=False)
31
await ctx.send(embed=embed)
32
conn.close()
33
The problem is this Discord Embed
There are 2 ‘Sunday’ which is not what i wanted. What i want is (example for Sunday), the ‘Value’ will showing ‘aot (eps :)’n’wataten (eps :)’ So that the result will showing this :
JavaScript
1
4
1
Sunday :
2
aot (eps : )
3
wataten (eps : )
4
I try to write this
JavaScript
1
3
1
Value=f'{for row in cursor7:
2
{row[0]}n}'
3
So that for every row in cursor 7, it will automatically creating a new line. But i know it wont working. Can someone help me please?
Advertisement
Answer
For your example, you can do
JavaScript
1
2
1
sunday_episodes = "n".join([f"{row[0]} (Eps : {row[1]})" for row in cursor7])
2
See: How would you make a comma-separated string from a list of strings?