#i need a hand with buttons

1 messages · Page 1 of 1 (latest)

idle prairie
#

anyone?

dark marsh
#

do you want to have multiple buttons?

idle prairie
#

one button to repeat the animal and then a dropdown to change it

#

thats what it looks like rn

dark marsh
#

do you have an API object instance or using async with?

idle prairie
#

im using aiohttp to send a request to an api

dark marsh
#

because if you created a api class you could use view rather than low-level

#

then you could use low-level and have a button handler

idle prairie
#
        elif selected== "Foxes":
            async with aiohttp.ClientSession() as session:
                async with session.get(f"https://some-random-api.ml/animal/fox") as resp:
                    data = json.loads(await resp.text())
                    foxEmbed = disnake.Embed(
                        title = "Foxes!",
                        colour = disnake.Colour.random()
                    ).set_image(
                        url = data['image']
                    ).set_footer(
                        text = data['fact'])
            await inter.response.send_message(embed = foxEmbed)
#

thats the base for it

#

i just change the session.get() url

#

and the selected

#

then the data parts

dark marsh
#

that with all animals?

#

you could simplify that

idle prairie
dark marsh
#

ah the api doesn't return the same data?

idle prairie
#

its random

#

and each api ahs a different json data layout

dark marsh
#

I mean for data other than the image

idle prairie
#

yeah the cat and dog apis have breed data

#

the fox one has fox facts

#

the duck one hasnt got anything besides a message saying powered by random-d.uk

dark marsh
#

ah

idle prairie
#

without taking it extremely complicated, this is as simple as ive got it

dark marsh
#

then send the embed with a button and listen for it

idle prairie
#

i had a previous version for the zookeeper using slash command parameters

dark marsh
#

don't forget to create a custom id with the endpoint

#

or well

#

the animal and you can have a dict with animal key and api value

idle prairie
#

might do a quick rewrite of sorts

#

because i think i found a way

#

but idk

#

because i dont know how to make it run the request again basically

#

without copy pasting the code

dark marsh
#

would be good to have an api class

#

so you have only one instance

idle prairie
#

sounds complicated