serenity-rs / poise

Discord bot command framework for serenity, with advanced features like edit tracking and flexible argument parsing
MIT License
678 stars 117 forks source link

How do i access `serenity::client::context` inside `poise::Context` #305

Closed 0xlosh closed 2 months ago

0xlosh commented 2 months ago

slash command example:

...
client.data.write().await.insert::<sleeper::RedisPool>(pool);
...

#[poise::command(slash_command)]
pub async fn block(ctx: Context<'_>, deployer: Address) -> Result<()> {
    let pool = ctx.data.read().await.get::<crate::RedisPool>()?;
    Ok(())
}

error: attempted to take value of method data on type poise::Context<'_, (), ErrReport> method, not a field im aware those are two different Context types, one is serenity::client::context, the other is poise::Context

for example in the Handler trait i have a different Context type, which can access data, how can i access that in my slash commands? i would like to share RedisPool in slash commands and in the Handler struct.

0xlosh commented 2 months ago

nvm literally just found it 5 seconds later, its ctx.serenity_context()

jamesbt365 commented 2 months ago

Use poise's data. Check out the examples.

0xlosh commented 2 months ago

Use poise's data. Check out the examples.

yes i could, but then i have to add it to both data fields (serenity context and pose::command context)

jamesbt365 commented 2 months ago

No you wouldnt, see the poise event handler example.

0xlosh commented 2 months ago

No you wouldnt, see the poise event handler example.

you are right, true. is there any disadvantage in using ctx.serenity_context() in the slash commands?

jamesbt365 commented 2 months ago

Yes, its fine, but you should do your command responses through poise's Context, feel free to use serenity's context to do other stuff as you please.

jamesbt365 commented 2 months ago

Just to let you know we have a discord server which you could use to ask questions instead of opening github issues. (https://discord.gg/serenity-rs)