I want to access that Context object, also pass it around into different functions. And use that ctx object into the function send_changes_via_bot, which would send the updates to discord's api using ctx.say().
I am also wondering if I am using rx right, I was thinking if I would recursively call the function the - rx being passed in each call would be different since it's continuously receiving from the tx in main. But now I am wondering if the old rx will just keep being copied as rx doesn't seem like a pointer.
pub async fn bot(rx: &mpsc::Receiver<Value>) { let discord_token = fs::read_to_string("discordtoken.txt") .expect("Issue with token"); let framework = poise::Framework::builder() .options(poise::FrameworkOptions { // Macro takes care of ctx and user commands: vec![account_age(), set_gdrive_channel(), spawn_watcher()], ..Default::default() }) .token(discord_token) .intents(serenity::GatewayIntents::non_privileged()) .setup(|ctx, _ready, framework| { Box::pin(async move { poise::builtins::register_globally(ctx, &framework.options().commands) .await?; Ok(Data {}) }) }); // * ---------------------------------------------------------------- // * ---------------------------------------------------------------- // ! Don't know how to pass context here :( send_changes_via_bot(ctx, rx).await; // * ---------------------------------------------------------------- // * ---------------------------------------------------------------- framework.run().await.unwrap(); } 21 Answer
This did the trick.
let metacat = framework.build().await.expect("Failed to init metacat"); metacat.client().start().await; let global_ctx = &metacat.client().cache_and_http; send_changes_via_bot(global_ctx, rx);