一个独立、简单易用、功能强大的基于交互的Discord机器人创建框架。由FastAPI提供支持
项目描述
📦 安装
最新稳定版
pip install dispike
📚 了解更多
🧑💻 快速入门示例
基本
from dispike import Dispike, DiscordCommand, DiscordResponse
from dispike import IncomingDiscordSlashInteraction
from dispike.helper import Embed
bot = Dispike(...)
command = DiscordCommand(
name="stock", description="Get the latest active stocks in the market!"
)
@bot.on("stock")
async def handle_stock_request(stockticker: str, ctx: IncomingDiscordSlashInteraction) -> DiscordResponse:
get_price = function(stockticker...)
embed=Embed()
embed.add_field(name="Stock Price for {stockticker}.", value="Current price is {get_price}", inline=True)
embed.set_footer(text="Request received by {ctx.member.user.username}")
return DiscordResponse(embed=embed)
if __name__ == "__main__":
bot.register(command)
bot.run()
高级
import dispike
from dispike import interactions, DiscordCommand, DiscordResponse
from dispike import IncomingDiscordSlashInteraction
from dispike.helper import Embed
class SampleGroupCollection(interactions.EventCollection):
def __init__(self):
self._api_key = "..."
def command_schemas(self):
return [
DiscordCommand(
name="lateststocks", description="Get the highest performing stocks in the market currently!"
),
interactions.PerCommandRegistrationSettings(
schema=DiscordCommand(
name="price",
description="return ticker price for server",
options=[],
),
guild_id=11111111,
)
]
def get_stock_information(self, stock_ticker):
return ...
def get_portfolio_stats(self, user_id):
return ...
@interactions.on("lateststocks")
async def latest_stocks(self, ctx: IncomingDiscordSlashInteraction) -> DiscordResponse:
embed = Embed()
# check user's porfolio by looking in the database by their discord ID
portfolio_stats = self.get_portfolio_stats(
ctx.member.user.id
)
embed.add_field(name="Stocks are doing good!", value=f"Current portfolio is {portfolio_stats}", inline=True)
embed.set_footer(text="Request received by {ctx.member.user.username}")
return DiscordResponse(embeds=[embed])
@interactions.on("price")
async def get_stock_price(self, ctx: IncomingDiscordSlashInteraction, ticker: str) -> DiscordResponse:
embed = Embed()
embed.add_field(name=f"Stock Price for 1.",
value=f"Current price is {self.get_stock_information(ticker)}", inline=True)
embed.set_footer(text="Request received by {ctx.member.user.username}")
return DiscordResponse(embeds=[embed])
## Inside seperate file
from dispike import Dispike, DiscordCommand
bot = Dispike(...)
bot.register_collection(SampleGroupCollection(), register_command_with_discord=True)
if __name__ == "__main__":
bot.run(port=5000)
Discord API 覆盖范围
查看覆盖范围
API端点 | 实现 |
---|---|
获取全局应用命令 | ✅ 已实现 |
创建全局应用命令 | ✅ 已实现 |
编辑全局应用命令 | ✅ 已实现 |
删除全局应用命令 | ✅ 已实现 |
创建公会应用命令 | ✅ 已实现 |
编辑公会应用命令 | ✅ 已实现 |
删除公会应用命令 | ✅ 已实现 |
创建交互响应 | ✅ 已实现 |
编辑原始交互响应 | ✅ 已实现 |
删除原始交互响应 | ✅ 已实现 |
创建后续消息 | ✅ 已实现 |
编辑后续消息 | ✅ 已实现 |
删除后续消息 | ✅ 已实现 |
数据模型和类型 | ✅ 已实现 |
ApplicationCommand | ✅ 已实现 |
ApplicationCommandOption | ✅ 已实现 |
ApplicationCommandOptionType | ✅ 已实现 |
ApplicationCommandOptionChoice | ✅ 已实现 |
Interaction | ✅ 已实现 |
Interaction Response | ✅ 已实现 |
消息组件 | ✅ 已实现 |
按钮(消息组件) | ✅ 已实现 |
操作行(消息组件) | ✅ 已实现 |
消息选择(消息组件) | ✅ 已实现 |
ℹ️ 注意
- Python 3.6+
- 不通过 Discord 网关进行通信。您需要的是 discord-py-slash-command。
- 您需要一个服务器来直接从 Discord 接收连接!
🧑💻 开发
需要帮助维护此库。请尽量将 PR 指向 dev
分支,并使用 black 格式化(如果可能)。
🎉 特别感谢
项目详情
下载文件
下载适用于您平台的文件。如果您不确定选择哪个,请了解有关 安装包 的更多信息。
源代码分发
dispike-1.0.1b0.tar.gz (39.9 kB 查看哈希)
构建分发
dispike-1.0.1b0-py3-none-any.whl (50.5 kB 查看哈希)
关闭
dispike-1.0.1b0.tar.gz 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 76e35cd778d8a85fd21ec34f6a088dfe457a379126376ace7262d5a73942459b |
|
MD5 | ab4d6070c271b0b22d44ade3d20191ae |
|
BLAKE2b-256 | 8d0259402415f6c5a72d41e50a3c462746592a34eb46762bb34b1a7e09abae49 |
关闭
dispike-1.0.1b0-py3-none-any.whl 的哈希
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 9b2e4ab983580cb736cf64b281470163b51b86fb319b9055fbcb5ea75e3f4343 |
|
MD5 | ac7b6da0a0bf7ef36976e8f6760c80d4 |
|
BLAKE2b-256 | ce36945ad69fd302530d44fa78e2309c9d171c5f6a77fe0b5dec79d5434878cd |