Skip to content
Edit this page View source of this page

Message Operations and Moderation

RustyCord now includes wrappers for common channel message operations, rich content, reactions, and basic guild administration.

Reply, edit, and delete

```rust,no_run // Reply while preserving the message reference. let reply = client .reply_to_message(channel_id, message_id, "Received!", None) .await?;

// Edit content, embeds, or both. None leaves that field unchanged. client .edit_message(channel_id, &reply.id, Some("Updated!".to_string()), None) .await?;

client .delete_message(channel_id, &reply.id) .await?;

The reply uses Discord's `message_reference` object. For lower-level control, construct `MessageReference::reply(channel_id, message_id)` and use `HTTPClient::send_message_with_reference`.

## Attachments and embeds

```rust,no_run
use rustycord::prelude::{FileAttachment, EmbedBuilder};

let embed = EmbedBuilder::new()
    .title("Report")
    .description("Generated report")
    .field("Rows", "42", true)
    .build();

client
    .send_embed_file_message(
        channel_id,
        "Here is the report:",
        vec![embed],
        vec![
            FileAttachment::new("./reports/report.csv")
                .filename("monthly-report.csv")
                .description("Monthly report"),
        ],
    )
    .await?;

Attachments are sent with Discord's multipart/form-data payload. File names and descriptions are derived automatically when not supplied. Files above the library's current 8 MiB bot-upload guard are rejected before the request is sent.

Reactions

```rust,no_run // Unicode emoji. client.add_reaction(channel_id, message_id, "👍").await?;

// Static or animated custom emoji notation. client .add_reaction(channel_id, message_id, "<:party:123456789>") .await?;

client .remove_reaction(channel_id, message_id, "👍") .await?;

Bots can also observe reaction events through `MessageHandler`:

```rust
#[async_trait]
impl MessageHandler for ReactionLogger {
    async fn on_reaction_add(
        &self,
        reaction: &ReactionEventPayload,
        _client: &Client,
    ) -> MessageHandlerResult {
        println!(
            "{} reacted with {:?}",
            reaction.user_id,
            reaction.emoji.name
        );
        Ok(())
    }
}

on_reaction_remove is available for removes. Enable the gateway reactions intent for guild reaction events.

Guild, channel, and role management

```rust,no_run let guild = client.get_guild(guild_id).await?; let channels = client.get_guild_channels(guild_id).await?;

client.create_channel( guild_id, CreateChannelRequest { name: "announcements".to_string(), r#type: Some(0), topic: Some("Project announcements".to_string()), parent_id: None, nsfw: None, rate_limit_per_user: None, }, ) .await?;

client .create_role( guild_id, serde_json::json!({"name": "Moderator", "color": 0x5865F2}), ) .await?;

client.modify_channel(channel_id, serde_json::json!({"topic": "Updated topic"})).await?; client.modify_role(guild_id, role_id, serde_json::json!({"mentionable": true})).await?; client.delete_channel(channel_id).await?; client.delete_role(guild_id, role_id).await?;

## Kick, ban, timeout, and roles

```rust,no_run
client.kick_member(guild_id, user_id).await?;

// Optionally remove recent messages while banning.
client.ban_member(guild_id, user_id, Some(1)).await?;
client.unban_member(guild_id, user_id).await?;

// Uses an ISO 8601 timestamp; `None` clears the timeout.
client
    .timeout_member(
        guild_id,
        user_id,
        Some("2026-12-05T00:00:00Z".to_string()),
    )
    .await?;

client.add_member_role(guild_id, user_id, role_id).await?;
client.remove_member_role(guild_id, user_id, role_id).await?;

The calling bot must hold the matching Discord permissions. Discord normally requires gateway intents for member operations and privileged intents for member-related event data.

Stability and rate limits

All crate-managed HTTP requests use per-major-resource rate-limit tracking, honor Retry-After, and delay requests when the current bucket is exhausted. Gateway shards reconnect on reconnect instructions and applicable close codes, preserve the session ID and sequence number, and send a RESUME payload when Discord allows it.

When reconnecting with a stored session, the gateway interval is replaced after each HELLO, so the shard does not reuse an invalid heartbeat interval across connections.