async fn cache_ready(&self, ctx: Context, _guilds: Vec<GuildId>) {
        println!("Cache built successfully!");

        // it's safe to clone Context, but Arc is cheaper for this use case.
        // Untested claim, just theoretically. :P
        let ctx = Arc::new(ctx);

        // We need to check that the loop is not already running when this event triggers,
        // as this event triggers every time the bot enters or leaves a guild, along every time the
        // ready shard event triggers.
        //
        // An AtomicBool is used because it doesn't require a mutable reference to be changed, as
        // we don't have one due to self being an immutable reference.
        if !self.is_loop_running.load(Ordering::Relaxed) {
            // We have to clone the Arc, as it gets moved into the new thread.
            let ctx1 = Arc::clone(&ctx);
            // tokio::spawn creates a new green thread that can run in parallel with the rest of
            // the application.

            let boticord_client = BoticordClient::new("boticord api token".to_string()).expect("failed client");

            tokio::spawn(async move {
                loop {
                    // We clone Context again here, because Arc is owned, so it moves to the
                    // new function.
                    post_boticord_stats_loop(Arc::clone(&ctx1), boticord_client.clone()).await;
                    tokio::time::sleep(Duration::from_secs(900)).await;
                }
            });

            // Now that the loop is running, we set the bool to true
            self.is_loop_running.swap(true, Ordering::Relaxed);
        }
    }
// We use the cache_ready event just in case some cache operation is required in whatever use
// case you have for this.
We use the cache_ready event just in case some cache operation is required in whatever use
case you have for this.
We use the cache_ready event just in case some cache operation is required in whatever use case you have for this .
async fn cache_ready(&self, ctx: Context, _guilds: Vec<GuildId>) {
        println!("Cache built successfully!");
        // it's safe to clone Context, but Arc is cheaper for this use case.
        // Untested claim, just theoretically. :P
        let ctx = Arc::new(ctx);
        // We need to check that the loop is not already running when this event triggers,
        // as this event triggers every time the bot enters or leaves a guild, along every time the
        // ready shard event triggers.
        //
        // An AtomicBool is used because it doesn't require a mutable reference to be changed, as
        // we don't have one due to self being an immutable reference.
        if !self.is_loop_running.load(Ordering::Relaxed) {
            // We have to clone the Arc, as it gets moved into the new thread.
            let ctx1 = Arc::clone(&ctx);
            // tokio::spawn creates a new green thread that can run in parallel with the rest of
            // the application.
            let boticord_client = BoticordClient::new("boticord api token".to_string()).expect("failed client");
            tokio::spawn(async move {
                loop {
                    // We clone Context again here, because Arc is owned, so it moves to the
                    // new function.
                    post_boticord_stats_loop(Arc::clone(&ctx1), boticord_client.clone()).await;
                    tokio::time::sleep(Duration::from_secs(900)).await;
                }
            });
            // Now that the loop is running, we set the bool to true
            self.is_loop_running.swap(true, Ordering::Relaxed);
        }
    }
async fn cache_ready ( & self , ctx : Context , _guilds : Vec < GuildId > ) { println ! ( " " ) ; // it's safe to clone Context, but Arc is cheaper for this use case. // Untested claim, just theoretically. :P let ctx = Arc :: new ( ctx ) ; // We need to check that the loop is not already running when this event triggers, // as this event triggers every time the bot enters or leaves a guild, along every time the // ready shard event triggers. // // An AtomicBool is used because it doesn't require a mutable reference to be changed, as // we don't have one due to self being an immutable reference. if ! self . is_loop_running . load ( Ordering :: Relaxed ) { // We have to clone the Arc, as it gets moved into the new thread. let ctx1 = Arc :: clone ( & ctx ) ; // tokio::spawn creates a new green thread that can run in parallel with the rest of // the application. let boticord_client = BoticordClient :: new ( " " . to_string ( ) ) . expect ( " " ) ; tokio :: spawn ( async move { loop { // We clone Context again here, because Arc is owned, so it moves to the // new function. post_boticord_stats_loop ( Arc :: clone ( & ctx1 ) , boticord_client . clone ( ) ) . await ; tokio :: time :: sleep ( Duration :: from_secs ( 900 ) ) . await ; } } ) ; // Now that the loop is running, we set the bool to true self . is_loop_running . swap ( true , Ordering :: Relaxed ) ; } }
We use the cache_ready event just in case some cache operation is required in whatever use
case you have for this.
We use the cache_ready event just in case some cache operation is required in whatever use case you have for this .
&self
ctx
Context
_guilds
Vec<GuildId>
&self
ctx
Context
_guilds
Vec<GuildId>