OpenTDB API的异步API包装。(https://opentdb.com/)

aiotrivia的Python项目详细描述


艾奥特里维亚

OpenTDB API的异步包装器

安装

$ pip install git+https://github.com/niztg/aiotrivia

示例用法

^{pr2}$

返回:

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

在不和.py命令用法

fromaiotriviaimportTriviaClient,AiotriviaExceptionfromdiscord.extimportcommandsimportasyncioimportrandomclassTriviaCog(commands.Cog):def__init__(self,bot):self.bot=botself.trivia=TriviaClient()@commands.command()asyncdeftrivia(self,ctx,difficulty):try:question=awaitself.trivia.get_random_question(difficulty)exceptAiotriviaExceptionaserror:returnawaitctx.send(f"{error.__class__.__name__}: {error}")answers=question.responsesrandom.shuffle(answers)final_answers='\n'.join([f"{index}. {value}"forindex,valueinenumerate(answers,1)])message=awaitctx.send(f"**{question.question}**\n{final_answers}\n{question.type.capitalize()} Question about {question.category}")answer=answers.index(question.answer)+1awaitself.trivia.close()# cleaning uptry:whileTrue:msg=awaitself.client.wait_for('message',timeout=15,check=lambdam:m.id!=message.id)ifstr(answer)inmsg.content:returnawaitctx.send(f"{answer} was correct! ({question.answer})")exceptasyncio.TimeoutError:awaitctx.send(f"The correct answer was {question.answer}")defsetup(bot):bot.add_cog(TriviaCog(bot))

For more info, read the documentation

Or join the discord server

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java如何将jaxb插件扩展与gradlejaxbplugin一起使用   java Hibernate列表<Object[]>到特定对象   java使用多态性显示arraylist的输出   java水平堆叠卡,带有一定偏移量   java错误:找不到符号方法liesInt()   java客户机/服务器文件收发中的多线程流管理   在java中可以基于访问重载方法吗?   包含空元素的java排序数组   swing Java按钮/网格布局   java BottomNavigationView getmaxitemcount   java空指针异常字符串生成器   java Xamarin升级导致“类文件版本错误52.0,应为50.0”错误   java我正在尝试打印它,而不只是对每一行进行println   Tomcat7中的java是否需要复制上下文。将xml转换为conf/Catalina/locahost以使其生效   带有注入服务的java REST端点在何处引发自定义WebServiceException?   在Java中使用GPS数据   java如何将JFreeChart ChartPanel导出到包含添加的CrosshairOverlay的图像对象?   内置Eclipse期间的Java 8堆栈溢出   java在GWT编译的JavaScript中如何表示BigDecimal