interaction response with for loop, discord py

Viewed 38

so in a command of my bot, i added a select menu, and in that i added options using a for loop, so, any way i can add response of those options using for loop too?

code:

@bot.hybrid_command()
async def nhentai(ctx, args):
    try:
        gallery = args
        pages = pageGet(gallery)
        links = pageLinks(gallery)
        view = View()

        with open('page.txt','w') as p:
            p.write('1')
        with open('page.txt','r+') as w:
            num = w.read()
            num = int(num)
        
        choose = Select(placeholder="Select Page")
        for option in range(1,int(pages+1)):
            choose.add_option(label=f"Page {option}")


        prev = Button(label='Previous', style=discord.ButtonStyle.grey, custom_id='prev')
        async def previous(interaction):
            with open('page.txt','r') as p:
                num = p.read()
                num = int(num)-1
            embed.set_image(url=f'{links[f"Page {num}"]}')
            embed.set_footer(text=f"Page {num}/{pages}")
            await interaction.response.edit_message(embed=embed,view=view)
            if num >=1:
                with open('page.txt','w') as dp:
                    dp.write(f'{num}')

        next = Button(label='Next', style=discord.ButtonStyle.grey, custom_id='next')
        async def nextt(interaction):
            with open('page.txt','r') as p:
                num = p.read()
                num = int(num)+1
            embed.set_image(url=f'{links[f"Page {num}"]}')
            embed.set_footer(text=f"Page {num}/{pages}")
            await interaction.response.edit_message(embed=embed,view=view)
            if num < 16:
                with open('page.txt','w') as dn:
                    dn.write(f'{num}')
        
        view.add_item(prev)
        view.add_item(next)
        view.add_item(choose)

        embed=discord.Embed(title=f"{gallery}", url=f"https://nhentai.net/g/{gallery}", color=0xff4d4d)
        embed.set_author(name="Nhentai", icon_url="https://archive.org/download/nhentai-logo-3/nhentai-logo-3.jpg")
        embed.set_image(url=f'{links[f"Page {num}"]}')
        embed.set_footer(text=f"Page {num}/{pages}")

        await ctx.send(embed=embed,view=view)
        prev.callback = previous
        next.callback = nextt
    except KeyError:
        with open('page.txt','w') as de:
            de.write(f'1')
        await ctx.send(embed=embed,view=view)
            
    
bot_start()

the value of pages could be any number

i want to add interaction response for every option added using the for loop too, please help.

0 Answers
Related