用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第三方库


热门话题
java线程;创建一个单独的线程来定期执行某些操作   用java将SonarQube升级到5.2失败。util。同时发生的CancellationException:空   在线程对象上调用start时,线程上设置的java优先级无效   java如何在不使用reduce()或last()折叠的情况下获取通量的最后一项   java如何从ArrayList中获取元素?   应用了逻辑的JavaTwitterAPI   在这种情况下,怎样才能不让自己重复?安卓的java   JavaAndroid:线程可运行和处理程序。在run方法中发布问题(Handler.postXX在预期情况下不会按时运行)   java log4j grok与管道故障   使用循环返回命令选项时出现问题/仅运行一个命令(JAVA)   java双重比较问题   使用vertx的JWT公钥/私钥身份验证中的java握手   用Java将WMA和AAC音频转换为MP3   解析字符串java get index   与具有不同数据类型的密钥同名的java JSON