Skip to main content

Bot

Trait Bot 

Source
pub trait Bot: Sized + BotBounds {
    // Required method
    fn run_until(
        self,
        shutdown: Shutdown,
    ) -> impl BotFutureBounds<Output = Result<(), BotError>>;

    // Provided method
    fn run(self) -> impl BotFutureBounds<Output = Result<(), BotError>> { ... }
}
Expand description

Unified Bot trait that hides connection mode differences

Every adapter — Discord’s gateway, Telegram’s long polling, and Matrix’s sync loop — exposes the same entry point: run until told to stop.

§Example

use botkit_core::{Bot, Shutdown};

// Run until the process is killed.
bot.run().await?;

// Or run until something else signals shutdown.
let (signal, shutdown) = Shutdown::channel();
let task = spawn(bot.run_until(shutdown));
signal.shutdown();
task.await?;

Required Methods§

Source

fn run_until( self, shutdown: Shutdown, ) -> impl BotFutureBounds<Output = Result<(), BotError>>

Run the bot until shutdown fires or a fatal error occurs

Returns Ok(()) when stopped via the shutdown signal.

Provided Methods§

Source

fn run(self) -> impl BotFutureBounds<Output = Result<(), BotError>>

Run the bot until a fatal error occurs

Equivalent to Bot::run_until with a signal that never fires.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§