You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 4, 2021. It is now read-only.
I got a little problem, I need to be able to access my database pool in on_message_create (and probably others) but I can't pass parameters to the function that is passed in it :
client.on_message_create(message_manage(pool); because it ask me to pass Session<()> and MessageCreate which are passed by default
Hi, you can use a global state, using panda::new_with_state(), there is an example in example directory.
I don't know what library are you using, so take this as an idea.
structGlobalState{database:MysqlPool}#[tokio::main]asyncfnmain() -> Result<(),Box<dyn std::error::Error>>{let state = GlobalState{database:MysqlPool::new("uri")};letmut client = panda::new_with_state("your token", state).await?;
client.on_message_create(message_manage);
client.start.await?;Ok(())}asyncfnmessage_manage(s:Session<GlobalState>,msg:MessageCreate) -> HandlerResult{let db_pool = &s.state.database;// if you need mutable you can use Mutex, in the state declaration.// for example, let state = GlobalState { datebase: Mutex::new(MysqlPool::new("uri")) }// Now you can use your db_poolOk(())}
Hi,
First, thanks for the lib!
I got a little problem, I need to be able to access my database pool in on_message_create (and probably others) but I can't pass parameters to the function that is passed in it :
client.on_message_create(message_manage(pool);
because it ask me to pass Session<()> and MessageCreate which are passed by defaultasync fn message_manage(s: Session<()>, msg: MessageCreate, pool: MysqlPool) -> HandlerResult {
How would you to it? Can I get Session and MessageCreate at this moment and pass them "manually"?
The text was updated successfully, but these errors were encountered: