Discord 的 Python 库
项目描述
# disco
Disco 是一个用于 [Discord API](https://discordapp.com/developers/docs/intro) 的简单且可扩展的库。加入官方频道并在 [此处] (https://discord.gg/WMzzPec) 聊天。
- 富有表现力、功能性的界面,不碍事
- 专为高性能和效率
而设计 - 可配置和模块化,满足您的需要
- 完全支持 Python 2.x/3.x
- 使用 Gevent 的事件网络和 IO
##安装
Disco 既可以作为通用库运行,也可以作为独立的 bot 工具包运行。安装 disco 就像运行 `pip install disco-py` 一样简单,但是建议高级用户使用一些额外的软件包,即:
|Name|Reason|
|----|--------|
|requests[security]|为正确的 SSL 实现添加包|
|ujson|更快的 json 解析器,提高性能|
|erlpack (2.x)、earl-etf (3.x)|ETF 解析器使用 --encoder=etf 标志运行|
|gipc|Gevent IPC,自动分片所需|
## 示例
使用内置机器人创作工具的简单机器人:
```python
from disco.bot import Bot, Plugin
class SimplePlugin(Plugin):
# 插件提供了一个简单的接口来监听 Discord 事件
@Plugin.listen('ChannelCreate')
def on_channel_create(self, event): event.channel.send_message
('Woah, a new channel huh!')
# 他们还提供了一个易于使用的命令组件
@Plugin.command('ping')
def on_ping_command(self, event):
event.msg.reply('Pong!')
# 其中包括命令参数解析
@Plugin.command('echo', '<content:str...>')
def on_echo_command(self, event, content):
event.msg.reply(content)
```
使用默认的机器人配置,我们现在可以像这样运行这个脚本:
`python -m disco.cli --token="MY_DISCORD_TOKEN" --run-bot --plugin simpleplugin`
并且可以通过提及机器人来触发命令(由 BotConfig.command\_require\_mention 标志配置):

Disco 是一个用于 [Discord API](https://discordapp.com/developers/docs/intro) 的简单且可扩展的库。加入官方频道并在 [此处] (https://discord.gg/WMzzPec) 聊天。
- 富有表现力、功能性的界面,不碍事
- 专为高性能和效率
而设计 - 可配置和模块化,满足您的需要
- 完全支持 Python 2.x/3.x
- 使用 Gevent 的事件网络和 IO
##安装
Disco 既可以作为通用库运行,也可以作为独立的 bot 工具包运行。安装 disco 就像运行 `pip install disco-py` 一样简单,但是建议高级用户使用一些额外的软件包,即:
|Name|Reason|
|----|--------|
|requests[security]|为正确的 SSL 实现添加包|
|ujson|更快的 json 解析器,提高性能|
|erlpack (2.x)、earl-etf (3.x)|ETF 解析器使用 --encoder=etf 标志运行|
|gipc|Gevent IPC,自动分片所需|
## 示例
使用内置机器人创作工具的简单机器人:
```python
from disco.bot import Bot, Plugin
class SimplePlugin(Plugin):
# 插件提供了一个简单的接口来监听 Discord 事件
@Plugin.listen('ChannelCreate')
def on_channel_create(self, event): event.channel.send_message
('Woah, a new channel huh!')
# 他们还提供了一个易于使用的命令组件
@Plugin.command('ping')
def on_ping_command(self, event):
event.msg.reply('Pong!')
# 其中包括命令参数解析
@Plugin.command('echo', '<content:str...>')
def on_echo_command(self, event, content):
event.msg.reply(content)
```
使用默认的机器人配置,我们现在可以像这样运行这个脚本:
`python -m disco.cli --token="MY_DISCORD_TOKEN" --run-bot --plugin simpleplugin`
并且可以通过提及机器人来触发命令(由 BotConfig.command\_require\_mention 标志配置):
