dcr

DCR - a Discord library for Crystal

docs

DCR

DCR is a Discord library for Crystal, aimed to be easy to use and have an object oriented interface.

DCR is a fork of discordcr, which is a Discord library aimed at minimalism.

User accounts are not officially supported by DCR.

Installation

Add this to your application's shard.yml:

dependencies:
  dcr:
    gitlab: zatherz/dcr

Usage

An example bot which responds to !ping commands can be found here.

A multi-command example can be found here.

Errors

Errors are divided into 3 "categories":

  • CodeError [Discord error] - raised when a REST request to Discord errors with a code and a descriptive message

  • StatusError [HTTP error] - raised when a REST request fails in a general way

  • DCRError [DCR error] - extended by dcr-specific errors, usually raised in various situations of DCR misuse (e.g. not_this_user.username = "abc")

Library structure

A short overview of library structure:

  • The Client class includes the REST module, which handles the REST Discord API, while Client handles the gateway/websocket connection. With this in mind, Client isn't ideal for gateway usage because of the complete absence of any sort of caching.

  • CachedClient extends Client, and it's what you want to use for bots. It implements a cache on top of Client, with essentially the same API.

  • The payloads contain methods which simplify the usage of the library. For example, instead of using this lengthy snippet to get the GuildMember behind a message:

    user = msg.author
    channel = msg.channel
    raise "Not a guild text channel" if !channel.is_a? GuildTextChannel
    member = client.get_guild_member user_id: user.id, guild_id: channel.guild_id
    

    You can use this simple, single method:

    member = msg.member!
    

    This is the biggest difference compared to discordcr.

Library documentation is available at https://zatherz.gitlab.io/dcr/

Contributors

[discordcr]

  • meew0 - creator, maintainer
  • RX14 - Crystal expert, maintainer

[dcr]

Repository

dcr

Owner
Statistic
  • 2
  • 1
  • 0
  • 0
  • 1
  • over 7 years ago
  • June 29, 2017
License

MIT License

Links
Synced at

Sun, 22 Dec 2024 00:04:31 GMT

Languages