Skip to content

Settings and storage

Declare settings in plugin-info.settings. PhoenixCord shows them on the plugin’s settings page, stores them, and returns the default until the user changes one.

settings: vec![Setting {
key: "autoDisable".into(),
description: "Automatically disable the toggle again after sending one message".into(),
kind: SettingKind::Boolean,
default: SettingValue::Boolean(true),
restart_needed: false,
}],
Kind Value Shown as
boolean boolean Switch
integer integer Number input
number number Number input
text text Text input
select(options) text (the option value) Dropdown
slider(range) number Slider
hidden any Not shown. For plugin data, typically JSON in a text value

Read and write them with host::get_setting and host::set_setting. Any change, from the user or the plugin, delivers event.setting-changed with the key.

fn setting(key: &str) -> bool {
matches!(host::get_setting(key), Some(SettingValue::Boolean(true)))
}

For settings that need more than the built-in kinds, list Hook::SettingsPanel and return an element from settings_panel. It is shown below the declared settings.

Each plugin has a private, persistent key-value store for data that is not a setting:

Function Does
host::storage_get(key) Read a value
host::storage_set(key, value) Write a value, saved immediately
host::storage_delete(key) Remove a value
host::storage_keys() List keys

Values are strings. Serialize structured data to JSON.