Discord.py google images search

Viewed 3920

I'm currently trying to make a discord bot that will send an image from google images based on specific commands, so if i say /dog it posts a random picture of a dog from google images. I'm new to creating discord bots, and i'm planning to make it in Python. I would appreciate it if someone helped me with a sample code that would give me an idea of how i would fetch the image from google images.

1 Answers

you can do it with some-random-api using aiohttp Client session

for an example code it should look something like this

    @commands.command(name='dog')
    async def random_dog(self, ctx):
        async with aiohttp.ClientSession() as cs:
            async with cs.get("https://random.dog/woof.json") as r:
                
                data = await r.json()
                embed = discord.Embed(
                    title="Doggo",
                    color = ctx.author.color
                )
                embed.set_image(url=data['url'])
                await ctx.send(embed=embed)
Related