discordapi的Python包装器
enddiscord的Python项目详细描述
现代的Python封装器,易于编写,易于使用。在
主要特点
- 现代pythonicapi使用async和await。在
- 适当的费率限制处理。在
- 100%覆盖支持的Discord API。在
- 在速度和内存方面都得到了优化。在
安装
需要Python 3.5.3或更高版本
要在没有完全语音支持的情况下安装库,只需运行以下命令:
# Linux/macOS python3 -m pip install -U discord.py # Windows py -3 -m pip install -U discord.py
否则,要获得语音支持,应运行以下命令:
^{pr2}$要安装开发版本,请执行以下操作:
$ git clone https://github.com/Rapptz/discord.py $ cd discord.py $ python3 -m pip install -U .[voice]
可选包
- PyNaCl(用于语音支持)
请注意,在Linux安装语音时,在运行上述命令之前,必须通过您最喜欢的软件包管理器(例如apt、dnf等)安装以下软件包:
- libffi dev(在某些系统上为libffi-devel)
- python开发(例如,python3.6的python3.6-dev)
简单的例子
importdiscordclassMyClient(discord.Client):asyncdefon_ready(self):print('Logged on as',self.user)asyncdefon_message(self,message):# don't respond to ourselvesifmessage.author==self.user:returnifmessage.content=='ping':awaitmessage.channel.send('pong')client=MyClient()client.run('token')
机器人示例
importdiscordfromdiscord.extimportcommandsbot=commands.Bot(command_prefix='>')@bot.command()asyncdefping(ctx):awaitctx.send('pong')bot.run('token')
您可以在examples目录中找到更多示例。在
- 项目
标签: