9 releases (breaking)

Uses old Rust 2015

0.8.1 Jan 2, 2021
0.8.0 Mar 25, 2017
0.7.0 Nov 4, 2016
0.6.0 Jun 30, 2016
0.1.0 Nov 27, 2015

#336 in Network programming

Download history 79/week @ 2020-10-02 89/week @ 2020-10-09 65/week @ 2020-10-16 76/week @ 2020-10-23 73/week @ 2020-10-30 82/week @ 2020-11-06 85/week @ 2020-11-13 84/week @ 2020-11-20 70/week @ 2020-11-27 93/week @ 2020-12-04 72/week @ 2020-12-11 35/week @ 2020-12-18 5/week @ 2020-12-25 77/week @ 2021-01-01 82/week @ 2021-01-08 74/week @ 2021-01-15

289 downloads per month
Used in dishub

MIT license

205KB
4.5K SLoC

discord-rs

Note: the current crates.io version of discord-rs requires an old version of OpenSSL and will likely not compile for you. Use a Git dependency instead:

[dependencies]
discord = { git = "https://github.com/SpaceManiac/discord-rs" }

discord-rs is a Rust client library for the Discord chat client's API.

The Discord API can be divided into three main components: the RESTful API to which calls can be made to take actions, a websocket-based permanent connection over which state updates are received, and the voice calling system.

Log in to Discord with Discord::new, new_cache, or from_bot_token as appropriate. The resulting value can be used to make REST API calls to post messages and manipulate Discord state. Calling connect() will open a websocket connection, through which events can be received. These two channels are enough to write a simple chatbot which can read and respond to messages.

For more in-depth tracking of Discord state, a State can be seeded with the ReadyEvent obtained when opening a Connection and kept updated with the events received over it.

To join voice servers, call Connection::voice to get a VoiceConnection and use connect to join a channel, then play and stop to control playback. Manipulating deaf/mute state and receiving audio are also possible.

For further details, browse the source or read the documentation. For examples, browse the examples directory.

Installation

On Windows, discord-rs currently requires a GNU-like environment. For details, read the installation guide.

On all platforms, discord-rs has several system dependencies, which should be installed as appropriate:

  • pkg-config
  • openssl
  • libsodium (if using voice)
  • opus (if using voice)
  • ffmpeg (if using ffmpeg features)
  • youtube-dl (if using youtube-dl features)

Dependencies

~7–11MB
~219K SLoC