Getting started
This guide builds a plugin in Rust, the language PhoenixCord’s own plugins are written in. For TypeScript, see TypeScript.
Set up the repository
Section titled “Set up the repository”-
Install Rust and pnpm. The repository pins the Rust toolchain and the
wasm32-wasip2target inrust-toolchain.toml. -
Clone PhoenixCord and run the test suite once.
Terminal window git clone https://github.com/Leclowndu93150/PhoenixCordcd PhoenixCordcargo xtask test
Create a plugin
Section titled “Create a plugin”-
Create
plugins/shout/Cargo.toml. Every directory inplugins/is a plugin crate.[package]name = "shout"version.workspace = trueedition.workspace = truerust-version.workspace = truelicense.workspace = truepublish.workspace = true[lib]crate-type = ["cdylib"][dependencies]phoenixcord-sdk = { path = "../../crates/sdk" }[lints]workspace = true -
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 fixadds the license header every source file needs. -
Build every plugin into
target/plugins.Terminal window cargo xtask plugins
Test it
Section titled “Test it”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.
Next steps
Section titled “Next steps”- Plugin basics covers metadata, lifecycle, events and state
- Messages and User interface cover the hooks
- Read the plugin rules before submitting a plugin