serenity-rs / poise

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

Can't stop the bot inside a command #195

Closed maxwai closed 1 year ago

maxwai commented 1 year ago

There doesn't seem to be a quit/stop command available in the ctx object to be able to do a stop command to stop the bot from discord directly.

In serenity this was added for this issue https://github.com/serenity-rs/serenity/issues/70 with this commit: https://github.com/serenity-rs/serenity/commit/561b0e38b4cda6661425f76c8d707d58d0f12d09

kangalio commented 1 year ago

Poise Context is a wrapper around serenity Context (and a few other fields). You can access the inner context with .serenity_context(). For example: ctx.serenity_context().quit()

maxwai commented 1 year ago

Yes I know about the .serenity_context() method. But if I try this I get following error:

error[E0599]: no method named `quit` found for reference `&poise::serenity_prelude::Context` in the current scope
  --> src/bot/commands.rs:64:28
   |
64 |     ctx.serenity_context().quit();
   |                            ^^^^ method not found in `&Context`

Do I maybe need to add a special serenity dependency in my Cargo.toml? Currently it looks like this:

[dependencies]
tokio = { version = "1.25.1", features = ["macros", "rt-multi-thread"] }
poise = "0.5.5"
...

I tried adding serenity = "0.11.6" but this doesn't help

maxwai commented 1 year ago

I found the problem. The quit Method was removed from Context and added as shutdown in the ShardManager so now I just need a way to access the ShardManager

kangalio commented 1 year ago

You can do that with .framework().shard_manager

maxwai commented 1 year ago

thx for the help