add skip command
This commit is contained in:
@@ -7,6 +7,9 @@ pub(crate) use leave::leave;
|
||||
mod pause;
|
||||
pub(crate) use pause::pause;
|
||||
|
||||
mod skip;
|
||||
pub(crate) use skip::skip;
|
||||
|
||||
mod play;
|
||||
pub(crate) use play::play;
|
||||
|
||||
|
||||
45
src/commands/skip.rs
Normal file
45
src/commands/skip.rs
Normal file
@@ -0,0 +1,45 @@
|
||||
use crate::state::State;
|
||||
use std::error::Error;
|
||||
use twilight_model::{
|
||||
gateway::payload::incoming::InteractionCreate,
|
||||
http::interaction::{InteractionResponse, InteractionResponseType},
|
||||
};
|
||||
use twilight_util::builder::InteractionResponseDataBuilder;
|
||||
|
||||
pub(crate) async fn skip(
|
||||
interaction: Box<InteractionCreate>,
|
||||
state: State,
|
||||
) -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
|
||||
tracing::debug!(
|
||||
"skip command in guild {:?} in channel {:?} by {:?}",
|
||||
interaction.guild_id,
|
||||
interaction.channel,
|
||||
interaction.author(),
|
||||
);
|
||||
|
||||
let Some(guild_id) = interaction.guild_id else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
if let Some(call_lock) = state.songbird.get(guild_id) {
|
||||
let call = call_lock.lock().await;
|
||||
call.queue().skip()?;
|
||||
}
|
||||
|
||||
let interaction_response_data = InteractionResponseDataBuilder::new()
|
||||
.content("Skipped the next track")
|
||||
.build();
|
||||
|
||||
let response = InteractionResponse {
|
||||
kind: InteractionResponseType::ChannelMessageWithSource,
|
||||
data: Some(interaction_response_data),
|
||||
};
|
||||
|
||||
state
|
||||
.http
|
||||
.interaction(interaction.application_id)
|
||||
.create_response(interaction.id, &interaction.token, &response)
|
||||
.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user