用python编写的discordbots.org的简单api包装器

dblp的Python项目详细描述


View on PyPiv0.3.1Documentation Status

用python编写的discordbots.org的简单api包装器

安装

通过PIP安装(推荐)

pip install dblpy

从源安装

pip install git+https://github.com/DiscordBotList/DBL-Python-Library

文件

可以找到文档here

特点

  • POST服务器计数
  • 获取机器人信息、服务器计数、投票信息
  • 获取所有机器人程序
  • 获取用户信息
  • 获取小部件(大部件和小部件),包括自定义部件有关详细信息,请参见discordbots.org/api/docs
  • 获取周末状态
  • 内置webhook,帮助您处理dbl upvots
  • 自动服务器计数发布
  • 通过API搜索机器人程序

其他信息

  • 在使用此库提供的webhook之前,请确保已指定端口打开。
  • webhook_port必须大于1024到49151。

示例

没有webhook:

importdblimportdiscordfromdiscord.extimportcommands,tasksimportasyncioimportloggingclassDBLAPI(commands.Cog):"""Handles interactions with the discordbots.org API"""def__init__(self,bot):self.bot=botself.token='dbl_token'# set this to your DBL tokenself.dblpy=dbl.DBLClient(self.bot,self.token)# The decorator below will work only on discord.py 1.1.0+# In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())@tasks.loop(minutes=30.0)asyncdefupdate_stats(self):"""This function runs every 30 minutes to automatically update your server count"""logger.info('Attempting to post server count')try:awaitself.dblpy.post_guild_count()logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))exceptExceptionase:logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__,e))# if you are not using the tasks extension, put the line belowawaitasyncio.sleep(1800)defsetup(bot):globalloggerlogger=logging.getLogger('bot')bot.add_cog(DBLAPI(bot))

使用webhook:

importdblimportdiscordfromdiscord.extimportcommands,tasksimportasyncioimportloggingclassDBLAPI(commands.Cog):"""Handles interactions with the discordbots.org API"""def__init__(self,bot):self.bot=botself.token='dbl_token'# set this to your DBL tokenself.dblpy=dbl.DBLClient(self.bot,self.token,webhook_path='/dblwebhook',webhook_auth='password',webhook_port=5000)# The decorator below will work only on discord.py 1.1.0+# In case your discord.py version is below that, you can use self.bot.loop.create_task(self.update_stats())@tasks.loop(minutes=30.0)asyncdefupdate_stats(self):"""This function runs every 30 minutes to automatically update your server count"""logger.info('Attempting to post server count')try:awaitself.dblpy.post_guild_count()logger.info('Posted server count ({})'.format(self.dblpy.guild_count()))exceptExceptionase:logger.exception('Failed to post server count\n{}: {}'.format(type(e).__name__,e))# if you are not using the tasks extension, put the line belowawaitasyncio.sleep(1800)@commands.Cog.listener()asyncdefon_dbl_vote(self,data):logger.info('Received an upvote')print(data)defsetup(bot):globalloggerlogger=logging.getLogger('bot')bot.add_cog(DBLAPI(bot))

使用autopost:

importdblimportdiscordfromdiscord.extimportcommandsclassDBLAPI(commands.Cog):"""Handles interactions with the discordbots.org API"""def__init__(self,bot):self.bot=botself.token='dbl_token'# set this to your DBL tokenself.dblpy=dbl.DBLClient(self.bot,self.token,autopost=True)# Autopost will post your guild count every 30 minutesasyncdefon_guild_post():print("Server count posted successfully")defsetup(bot):bot.add_cog(DBLAPI(bot))

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

推荐PyPI第三方库


热门话题
google chrome我在哪里可以下载Mac OSX Lion的Java 6?   java管道化hadoop映射减少作业   java避免在使用jsoup解析html时删除空格和换行符   java将arrayList中的元素相互比较   如何创建一个计算一组数字之和的程序(Java)?   java JavaFX 8 JVM在退出后保留   升华文本3升华文本3 Java交互控制台?   JAVAutil。扫描仪和维基百科   java Android在RecyclerView中更新TextClock的时间格式(12/24小时格式)   java集合,如果达到限制,则可以在添加新项之前删除旧项   hex Java将十六进制转换为带符号的8位代码   java如何使用SQL中其他列的数据?   java如何确保返回指定类型的列表?   列出如何在java中声明匿名arraylist?   在JavaSpringBoot中使用RESTXML文件   使用Java在ColdFusion中计算HMACSHA256摘要的加密