Reputation: 342
I asked previous question about how to match elements in lists (it might be important to helping me on this question):
Comparing matching elements of a list in Python
I want to use J
which was my desired result of the previous question to either fill the embed.field.names or description of an embed. But the problem is that it just adds a single field with the first result and sends the embed, then sends another embed with the next result, and so on. The page = 1
in parameters is not used yet but I want to use it for page numbers so I can view 25 at a time within a single embed.
I hope this makes sense and thank you to whoever helps me :)
async def test(self, ctx, page = 1):
scan = f"privatelink"
async with aiohttp.ClientSession() as cs:
async with cs.get(scan) as r:
try: bag = ast.literal_eval(await r.text())
except: bag = json.loads(await r.text())
scan2 = 'privatelink'
async with aiohttp.ClientSession() as cs:
async with cs.get(scan2) as r:
c = json.loads(await r.text())
if bag == []:
await ctx.send("None")
return
bag = bag[0]['items']
emj = c['smiley']
nam = c['words']
for x in emj:
if x in bag:
for x in [emj.index(x)]:
J = c['words'][x]
e = discord.Embed(title=f"Test", color=discord.Colour(value=1111111),
description=f'')
e.add_field(name=J, value=f"")
await ctx.send(embed=e)
I just want to include up to 25 results within the same embed message. I don't want the bot to send a new message for every result.
Upvotes: 0
Views: 266
Reputation: 273
You've got your logic a big wrong. You created a new Embed for each x in the loop and you sent it inside the loop. If you create the Embed before you loop and send it when the loop is finished you will have an Embed with multiple fields
e = discord.Embed(title=f"Test", color=discord.Colour(value=1111111),
description=f'')
for x in [emj.index(x)]:
J = c['words'][x]
e.add_field(name=J, value=f"")
await ctx.send(embed=e)
You might also want to watch out with using the same variable name for nested loops If you have a for x in a for x loop you will change the x and it's confusing. Instead you can have one that is 'for emoji in emojis' and then the nested one is for x in [emj.index(x)] I hope I understood your question correctly
Upvotes: 1