Advertisement
Guest User

Untitled

a guest
Dec 12th, 2017
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.53 KB | None | 0 0
  1. # discord.py
  2.  
  3. [![PyPI](https://img.shields.io/pypi/v/discord.py.svg)](https://pypi.python.org/pypi/discord.py/)
  4. [![PyPI](https://img.shields.io/pypi/pyversions/discord.py.svg)](https://pypi.python.org/pypi/discord.py/)
  5.  
  6. discord.py is an API wrapper for Discord written in Python.
  7.  
  8. This was written to allow easier writing of bots or chat logs. Make sure to familiarise yourself with the API using the [documentation][doc].
  9.  
  10. [doc]: http://discordpy.rtfd.org/en/latest
  11.  
  12. ### Breaking Changes
  13.  
  14. The discord API is constantly changing and the wrapper API is as well. There will be no effort to keep backwards compatibility in versions before `v1.0.0`.
  15.  
  16. I recommend that you follow the discussion in the [unofficial Discord API discord channel][ch] and update your installation periodically. I will attempt to make note of breaking changes in the API channel so make sure to subscribe to library news by typing `?sub news` in the channel.
  17.  
  18. [ch]: https://discord.gg/0SBTUU1wZTUzBx2q
  19.  
  20. ## Installing
  21.  
  22. To install the library without full voice support, you can just run the following command:
  23.  
  24. ```
  25. python3 -m pip install -U discord.py
  26. ```
  27.  
  28. Otherwise to get voice support you should run the following command:
  29.  
  30. ```
  31. python3 -m pip install -U discord.py[voice]
  32. ```
  33.  
  34. To install the development version, do the following:
  35.  
  36. ```
  37. python3 -m pip install -U https://github.com/Rapptz/discord.py/archive/master.zip#egg=discord.py[voice]
  38. ```
  39.  
  40. or the more long winded from cloned source:
  41.  
  42. ```
  43. $ git clone https://github.com/Rapptz/discord.py
  44. $ cd discord.py
  45. $ python3 -m pip install -U .[voice]
  46. ```
  47.  
  48. Please note that on Linux installing voice you must install the following packages via your favourite package manager (e.g. `apt`, `yum`, etc) before running the above command:
  49.  
  50. - libffi-dev (or `libffi-devel` on some systems)
  51. - python<version>-dev (e.g. `python3.5-dev` for Python 3.5)
  52.  
  53. ## Quick Example
  54.  
  55. ```py
  56. import discord
  57. import asyncio
  58.  
  59. client = discord.Client()
  60.  
  61. @client.event
  62. async def on_ready():
  63. print('Logged in as')
  64. print(client.user.name)
  65. print(client.user.id)
  66. print('------')
  67.  
  68. @client.event
  69. async def on_message(message):
  70. if message.content.startswith('!test'):
  71. counter = 0
  72. tmp = await client.send_message(message.channel, 'Calculating messages...')
  73. async for log in client.logs_from(message.channel, limit=100):
  74. if log.author == message.author:
  75. counter += 1
  76.  
  77. await client.edit_message(tmp, 'You have {} messages.'.format(counter))
  78. elif message.content.startswith('!sleep'):
  79. await asyncio.sleep(5)
  80. await client.send_message(message.channel, 'Done sleeping')
  81.  
  82. client.run('token')
  83. ```
  84.  
  85. Note that in Python 3.4 you use `@asyncio.coroutine` instead of `async def` and `yield from` instead of `await`.
  86.  
  87. You can find examples in the examples directory.
  88.  
  89. ## Requirements
  90.  
  91. - Python 3.4.2+
  92. - `aiohttp` library
  93. - `websockets` library
  94. - `PyNaCl` library (optional, for voice only)
  95. - On Linux systems this requires the `libffi` library. You can install in
  96. debian based systems by doing `sudo apt-get install libffi-dev`.
  97.  
  98. Usually `pip` will handle these for you.
  99.  
  100. ## Related Projects
  101.  
  102. - [discord.js](https://github.com/discord-js/discord.js)
  103. - [discord.io](https://github.com/izy521/discord.io)
  104. - [Discord.NET](https://github.com/RogueException/Discord.Net)
  105. - [DiscordSharp](https://github.com/Luigifan/DiscordSharp)
  106. - [Discord4J](https://github.com/knobody/Discord4J)
  107. - [discordrb](https://github.com/meew0/discordrb)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement