Skip to main content

Asynchronous API Wrapper for the OpenTDB Api. (

Project description


Async Wrapper for the OpenTDB API


$ pip install git+

Example Usage

import asyncio
import aiotrivia

client = aiotrivia.TriviaClient()

async def main():
    data = await client.get_specific_question(category=20)
    for i in data:
        print('%s | %s' % (i.question, i.responses))
    await client.close() # after you're done with everything



Which figure from Greek mythology traveled to the underworld to return his wife Eurydice to the land of the living? | ['Daedalus', 'Hercules', 'Perseus', 'Orpheus'] command usage

from aiotrivia import TriviaClient, AiotriviaException
from discord.ext import commands
import asyncio
import random

class TriviaCog(commands.Cog):
    def __init__(self, bot): = bot
        self.trivia = TriviaClient()

    async def trivia(self, ctx, difficulty):
            question = await self.trivia.get_random_question(difficulty)
        except AiotriviaException as error:
            return await ctx.send(f"{error.__class__.__name__}: {error}")
        answers = question.responses
        final_answers = '\n'.join([f"{index}. {value}" for index, value in enumerate(answers, 1)])
        message = await ctx.send(f"**{question.question}**\n{final_answers}\n{question.type.capitalize()} Question about {question.category}")
        answer = answers.index(question.answer)+1
        await self.trivia.close() # cleaning up
            while True:
                msg = await self.client.wait_for('message', timeout=15, check=lambda m: !=
                if str(answer) in msg.content:
                    return await ctx.send(f"{answer} was correct! ({question.answer})")
        except asyncio.TimeoutError:
            await ctx.send(f"The correct answer was {question.answer}")

def setup(bot):

For more info, read the documentation

Or join the discord server

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiotrivia-2.0.1.tar.gz (4.6 kB view hashes)

Uploaded source

Built Distribution

aiotrivia-2.0.1-py3-none-any.whl (6.2 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page