另一个简单的类包装器,用于在Python3中与不一致的webhook交互
dhooks-lite的Python项目详细描述
dhooks精简版
目录
概述
dhooks lite是一个库,其中包含一组类,用于与用python3编写的不一致webhook进行交互。在
此库旨在通过以下特性与类似库区分:
- 可在任何Python3版本上运行,包括旧版本(如3.4、3.5.2)
- 经过全面测试
- 使用简单(只有一种方法,属性和对象的名称与official Discord documentation中的名称相同)
- 有日志记录
- 请求会自动重试,并有合理的超时
功能
此库提供以下功能:
- 通过webhooks在不和谐频道中发布消息(仅限同步调用)
- 将嵌入项附加到消息
- 检索发送报告和不一致
- 从不一致中检索HTTP状态和标头,例如用于实现速率限制处理
示例
下面是一些关于如何在Python脚本中使用dhookslite的示例。在
请注意,您还可以在这个repo的/examples
文件夹中找到所有示例的源代码。在
你好世界
发布消息的最小示例。在
fromdhooks_liteimportWebhookhook=Webhook(DISCORD_WEBHOOK_URL)hook.execute('Hello, World!')
使用自定义头像发布
在这个例子中,我们设置用户名和头像。在
^{pr2}$使用embeds
完成示例最后,下面是一个使用两个嵌入内容并使用所有可用功能的示例(简称):
importdatetimefromdhooks_liteimportWebhook,Embed,Footer,Image,Thumbnail,Author,Fieldhook=Webhook(DISCORD_WEBHOOK_URL)e1=Embed(description='Only a few years ago, scientists stumbled upon an electrical current of cosmic proportions.(...)',title='Universe\'s highest electric current found',url='https://www.newscientist.com/article/mg21028174-900-universes-highest-electric-current-found/',timestamp=datetime.datetime.utcnow(),color=0x5CDBF0,footer=Footer('Science Department','https://i.imgur.com/Bgsv04h.png'),image=Image('https://i.imgur.com/eis1Y0P.jpg'),thumbnail=Thumbnail('https://i.imgur.com/2A4k28x.jpg'),author=Author('John Scientist',url='https://en.wikipedia.org/wiki/Albert_Einstein',icon_url='https://i.imgur.com/1JoHDw1.png'),fields=[Field('1st Measurement','Failed'),Field('2nd Measurement','Succeeded')])e2=Embed(description="TOP SECRET - Do not distribute!")hook.execute('Checkout this new report from the science department:',username='Bruce Wayne',avatar_url='https://i.imgur.com/thK8erv.png',embeds=[e1,e2],wait_for_response=True)
安装
您可以直接从PyPI安装此库:
pip install dhooks-lite
文件
有关所有类的完整文档,请参阅官方文档here。在
贡献
我们欢迎任何贡献!在
如果你发现了一个错误或有一个功能要求,请提出一个问题。在
如果您想帮助进一步改进此库,请随时发出合并请求。变更时请遵守以下要求:
- 代码应符合PEP8
- 单元测试完全超期
- 所有类都应该是不可变的
- 所有类及其公共方法都必须有docstring文档
- 所有变更必须记录在变更日志中
- 项目
标签: