Skip to content

Getting started

This guide builds a plugin in Rust, the language PhoenixCord’s own plugins are written in. For TypeScript, see TypeScript.

  1. Install Rust and pnpm. The repository pins the Rust toolchain and the wasm32-wasip2 target in rust-toolchain.toml.

  2. Clone PhoenixCord and run the test suite once.

    Terminal window
    git clone https://github.com/Leclowndu93150/PhoenixCord
    cd PhoenixCord
    cargo xtask test
  1. Create plugins/shout/Cargo.toml. Every directory in plugins/ is a plugin crate.

    [package]
    name = "shout"
    version.workspace = true
    edition.workspace = true
    rust-version.workspace = true
    license.workspace = true
    publish.workspace = true
    [lib]
    crate-type = ["cdylib"]
    [dependencies]
    phoenixcord-sdk = { path = "../../crates/sdk" }
    [lints]
    workspace = true
  2. Create plugins/shout/src/lib.rs.

    use phoenixcord_sdk::Plugin;
    use phoenixcord_sdk::types::{Hook, OutgoingMessage, PluginInfo, SendDecision};
    #[derive(Default)]
    struct Shout;
    impl Plugin for Shout {
    fn info() -> PluginInfo {
    PluginInfo {
    tags: vec!["Chat".into()],
    hooks: vec![Hook::MessagePreSend],
    ..PluginInfo::new("Shout", "Sends every message in capitals", &["you"])
    }
    }
    fn pre_send(&mut self, message: OutgoingMessage) -> SendDecision {
    SendDecision::Replace(message.content.to_uppercase())
    }
    }
    phoenixcord_sdk::plugin!(Shout);

    cargo xtask fix adds the license header every source file needs.

  3. Build every plugin into target/plugins.

    Terminal window
    cargo xtask plugins

crates/host/tests/plugins.rs loads the built plugins into the real plugin host with a mock Discord client. Add a test next to the existing ones:

#[test]
fn shout_capitalises_messages() {
let mut fixture = fixture("shout", &["Shout"]);
assert_eq!(send(&mut fixture.host, "hello").as_deref(), Some("HELLO"));
}

Then run cargo xtask test, which also checks formatting, lints and license headers.