A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.

Overview

rs-cord

rs-cord

A high-level Rust crate around the Discord API, aimed to be easy and straight-forward to use.
DocumentationCrates.ioDiscord


Navigation

Motive

Currenty, the leading crates that wrap around Discord's API (e.g. serenity), although some relatively high level, do not provide as much abstraction as I would like and requires lots of concepts - ones that are common in other frameworks - to be done manually.

Take asset/avatar handling. discord.py does this pretty well:

The equivalent of member.avatar.replace(format="png", size=2048) in an existing Rust crate, such as serenity would be:

format!("https://cdn.discordapp.com/avatars/{}/{}.png?size={}", member.user.id, member.user.avatar, 2048)  // Verbose for what?
// or
member.face().replace(".webp", ".png") + "?size=2048"  // Not elegant

(For clarification, I have nothing against serenity; it's a pretty good crate.)

rs-cord has been designed with two things in mind: elegance and performance.

Elegance

Assets

rs-cord takes a different approach to assets and avatars than serenity. The Asset struct will fulfill all your needs:

user.avatar().with_format("png").with_size(2048).url()

No more member.user.x

Discord's API has a nested user in member objects. Many Rust crates do not merge these two, which can cause confusion to the user.

rs-cord merges all fields from User into Member:

println!("Hello {}", member.name);

Installation

Just like with every other Rust crate, insert it into your Cargo.toml file:

[dependencies]
rs-cord = "0"

Installing from GitHub

If you would like to use the most recent update of rs-cord, make sure you have git installed and insert the following into your Cargo.toml:

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

Note that for production usage, it is recommended to stay with a stable version upload on crates.io.

Documentation for the GitHub version is available here.

Getting Started

You may see the examples folder for code examples.

Example Ping-pong Bot:

use rs_cord::{Client, ClientState, EventListener};
use rs_cord::events::{ReadyEvent, MessageCreateEvent};
use rs_cord::intents;

struct Listener;

#[rs_cord::async_trait]
impl EventListener for Listener {
    async fn ready(state: &ClientState, _event: &ReadyEvent) {
        println!("Logged in as {} (ID: {})", state.user.tag(), state.user.id);
    }

    async fn message_create(state: &ClientState, event: &MessageCreateEvent) {
        if event.message.content == "ping" {
            event.message.reply("Pong!");
        }
    }
}

#[tokio::main]
async fn main() {
    Client::new_with_token("my secret token")
        .with_intents(intents!(GUILDS, MESSAGES))
        .with_event_listener(Listener)
        .start()
        .await
        .expect("failed to start client");
}

Need help?

You can join our Discord server in order to get help on all things rs-cord.

Contributing

We appreciate all of your contributions! Please read CONTRIBUTING.md for instructions on how to contribute.

Links

You might also like...
A Discord bot for sending GeoGuessr challenge links that uses the GeoGuessr API written in rust.

GeoGuessr-bot-rs This is a simple implementation of a discord bot that send GeoGuessr-challenge links on demand. Features: Slash-commands Lightning-fa

Serenity is a Rust library for the Discord API
Serenity is a Rust library for the Discord API

serenity Serenity is a Rust library for the Discord API. View the examples on how to make and structure a bot. Serenity supports bot login via the use

A minimal discord api wrapper.

descord Descord is a discord api wrapper. Example use descord::prelude::*; #[tokio::main] async fn main() { let mut client = Client::new(

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine
MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine

MeiliSearch is a powerful, fast, open-source, easy to use and deploy search engine. Both searching and indexing are highly customizable. Features such as typo-tolerance, filters, and synonyms are provided out-of-the-box. For more information about features go to our documentation.

Easy-to-use optional function arguments for Rust

OptArgs uses const generics to ensure compile-time correctness. I've taken the liberty of expanding and humanizing the macros in the reference examples.

Just a personal Rust Playground to play around and understand the language.
Just a personal Rust Playground to play around and understand the language.

Rust Proactive Introduction The code is a bit messy but it serves just as a personal Rust Playground to play around and understand the language. You c

📦  Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate.
📦 Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate.

📦 Crate Protocol Crate Protocol allows anyone to create, manage, and trade a tokenized basket of assets, which we refer to as a Crate. A Crate is alw

FFI wrapper around cfitsio in Rust

rust-fitsio FFI wrapper around cfitsio in Rust Installation fitsio supports versions of cfitsio = 3.08. cfitsio must be compiled with reentrant suppo

Thin wrapper around starship.rs to format kakoune status line

kakship is just a thin wrapper around starship to format the status line of kakoune and is meant to be used with the included kakoune script kakship.kak.

Owner
Jay3332
i don't know.
Jay3332
Amethyst is a systems language aimed at being simple, small, portable, and safe.

amethyst Amethyst is a systems language aimed at being simple, small, portable, and safe. What is this language? From the r/ProgLangs discord server:

Amethyst Language 34 Dec 18, 2022
A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns.

Discord API Types A repository full of manually generated hand curated JSON files, which contain the API Types that the Discord API returns. Also did

Unofficial Discord Documentation 1 Sep 16, 2022
A rust(serenity) based discord bot for the hacksquad discord server

A Discord Bot for Hacksquad How to Deploy? Requirements Docker Docker Compose Steps To Run Copy the docker-compose.yml and .env.example files to your

HackSquad 5 Jan 4, 2023
A Discord bot focused on addressing the inherent problems with Discord, to allow a more socialist/anarchist organization of servers.

ACABot A Discord bot focused on addressing the inherent problems with Discord, to allow a more socialist/anarchist organization of servers (or "guilds

null 4 May 3, 2022
High-level PortMidi bindings and wrappers for Rust

High-level PortMidi bindings and wrappers for Rust

Philippe Delrieu 69 Dec 1, 2022
A simple, yet feature-filled wrapper around the coqui-stt C API

A simple, yet feature-filled wrapper around the coqui-stt C API

0/0 56 Jan 3, 2023
A safe wrapper around Gamercade's raw Api.

gamercade-rs A safe wrapper around Gamercade's Raw Api. As the Raw Api requires using a lot of unsafe and hiding of values through different types (fo

null 1 Aug 23, 2022
High-level, optionally asynchronous Rust bindings to llama.cpp

llama_cpp-rs Safe, high-level Rust bindings to the C++ project of the same name, meant to be as user-friendly as possible. Run GGUF-based large langua

Binedge.ai 4 Nov 21, 2023
Powerfull Discord Raid Bot written in Rust, use VPN / Proxy because creating 200 channels in 10s Will ratelimit you.

Harakiri-Rust This the first Discord Raid Bot made in RustLang I recommend you use with a VPN or a Proxy to evade Discord Ratelimit. If bot doesn't st

Marco 6 May 1, 2023
An abstraction build on top of discord-rich-presence that makes possible to use it in a more declarative way

Declarative Discord Rich Presence This library is an abstraction build on top of discord-rich-presence crate that allows you to use it in a more decla

null 2 Sep 7, 2022