Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I have tried to work with poise but can't get it to work. #200

Closed
rejafdofs opened this issue Oct 13, 2023 · 2 comments
Closed

I have tried to work with poise but can't get it to work. #200

rejafdofs opened this issue Oct 13, 2023 · 2 comments
Labels
question Further information is requested serenity Relates to using Songbird with the Serenity library wontfix This will not be worked on

Comments

@rejafdofs
Copy link

///example
#[poise::command(slash_command, prefix_command)]
async fn mogetama(
    ctx:poise::Context<'a, Data, Box<dyn std::error::Error + Send + Sync>>,
) -> Result<(), Error> {
  let context = match ctx {
                poise::Context::Application(x) => x.serenity_context,
                poise::Context::Prefix(y) => y.serenity_context,
            };
             let a=songbird::get(context)
        .await

    Ok(())
}

If you do this, a will always be set to none when the user is in the voice channel.
Is it possible to use a bot created with poise?

@flashgnash
Copy link

flashgnash commented Oct 11, 2024

Isn't serenity_context a function not a property?

#[poise::command(slash_command, prefix_command)]
async fn join_vc(ctx: Context<'_>) -> Result<(), Error> {

    let (guild_id, channel_id) = {
        let guild = ctx.guild().unwrap();
        let channel_id = guild
            .voice_states
            .get(&ctx.author().id)
            .and_then(|voice_state| voice_state.channel_id);

        (guild.id, channel_id)
    };

    let connect_to = match channel_id {
        Some(channel) => channel,
        None => {
            ctx.reply("Not in a voice channel").await;

            return Ok(());
        },
    };

    let manager = songbird::get(ctx.serenity_context())
        .await
        .expect("Songbird Voice client placed in at initialisation.")
        .clone();

    if let Ok(handler_lock) = manager.join(guild_id, connect_to).await {
        // Attach an event handler to see notifications of all track errors.
        println!("Success!");
    }
  
        
    Ok(())
}

Using this (join command example modified to work with poise) I've managed to get the bot to connect to a voice channel with no issue

@GnomedDev GnomedDev added question Further information is requested wontfix This will not be worked on serenity Relates to using Songbird with the Serenity library labels Oct 11, 2024
@GnomedDev
Copy link
Member

If songbird::get(ctx) is returning None, that means you have not called register_songbird on the serenity::ClientBuilder as the documentation says to do.

In future, please ask for help in the serenity-rs discord server.

@GnomedDev GnomedDev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested serenity Relates to using Songbird with the Serenity library wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants