PokeAPI / pokebase

Python 3 wrapper for Pokéapi v2
BSD 3-Clause "New" or "Revised" License
286 stars 53 forks source link

How do i get the types of the pokemon? #22

Closed ghost closed 4 years ago

ghost commented 4 years ago

I have been working on a project which gives the stats of pokemon. How do i get the types of the pokemon with discord.py?

@bot.command()
async def poketype(ctx, pokemon):

    poke= pokebase.APIResource('pokemon', pokemon)
    await ctx.send(poke.types())

bot.load_extension("jishaku") #for debugging
bot.run('BOT TOKEN')

i get: discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: 'list' object is not callable

C-Garza commented 4 years ago

The pokemon endpoint gives type as a list as seen here in the docs and it looks like you're trying to invoke it like a function with this line here: await ctx.send(poke.types()).

I'm not too familiar with discord.py, but I think you can access the pokemon's type with something like this: poke.types[0].type. That would give you one of the types the pokemon has. You can see the structure of the API with the link to the docs I linked above.

Naramsim commented 4 years ago

Pokebase returns a dict object apparently, so you access it like: poke.types

Remember that the .types property will be itself a list of dicts.

types: [
    {
        slot: 1,
        type: {
        name: "water",
            url: "https://pokeapi.co/api/v2/type/11/"
        }
    }
],