Add option for playing in separate channel
Play sounds in another channel even if not connected.
This commit is contained in:
parent
64e7eb4a53
commit
6307de331d
@ -1,4 +1,7 @@
|
|||||||
use poise::serenity::{builder::CreateActionRow, model::application::component::ButtonStyle};
|
use poise::{
|
||||||
|
serenity::{builder::CreateActionRow, model::application::component::ButtonStyle},
|
||||||
|
serenity_prelude::GuildChannel,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
cmds::autocomplete_sound,
|
cmds::autocomplete_sound,
|
||||||
@ -14,23 +17,32 @@ pub async fn play(
|
|||||||
#[description = "Name or ID of sound to play"]
|
#[description = "Name or ID of sound to play"]
|
||||||
#[autocomplete = "autocomplete_sound"]
|
#[autocomplete = "autocomplete_sound"]
|
||||||
name: String,
|
name: String,
|
||||||
|
#[description = "Channel to play in (default: your current voice channel)"] channel: Option<
|
||||||
|
GuildChannel,
|
||||||
|
>,
|
||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
ctx.defer().await?;
|
ctx.defer().await?;
|
||||||
|
|
||||||
let guild = ctx.guild().unwrap();
|
let guild = ctx.guild().unwrap();
|
||||||
|
|
||||||
|
if channel.as_ref().map_or(false, |c| c.is_text_based()) {
|
||||||
|
ctx.say("The channel specified is not a voice channel.")
|
||||||
|
.await?;
|
||||||
|
} else {
|
||||||
ctx.say(
|
ctx.say(
|
||||||
play_from_query(
|
play_from_query(
|
||||||
&ctx.discord(),
|
&ctx.discord(),
|
||||||
&ctx.data(),
|
&ctx.data(),
|
||||||
guild,
|
guild,
|
||||||
ctx.author().id,
|
ctx.author().id,
|
||||||
|
channel.map(|c| c.id),
|
||||||
&name,
|
&name,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
.await,
|
.await,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -224,6 +236,7 @@ pub async fn loop_play(
|
|||||||
&ctx.data(),
|
&ctx.data(),
|
||||||
guild,
|
guild,
|
||||||
ctx.author().id,
|
ctx.author().id,
|
||||||
|
None,
|
||||||
&name,
|
&name,
|
||||||
true,
|
true,
|
||||||
)
|
)
|
||||||
|
@ -142,6 +142,7 @@ SELECT name, id, public, server_id, uploader_id
|
|||||||
&data,
|
&data,
|
||||||
guild_id.to_guild_cached(&ctx).unwrap(),
|
guild_id.to_guild_cached(&ctx).unwrap(),
|
||||||
component.user.id,
|
component.user.id,
|
||||||
|
None,
|
||||||
&component.data.custom_id,
|
&component.data.custom_id,
|
||||||
false,
|
false,
|
||||||
)
|
)
|
||||||
|
@ -104,15 +104,18 @@ pub async fn play_from_query(
|
|||||||
data: &Data,
|
data: &Data,
|
||||||
guild: Guild,
|
guild: Guild,
|
||||||
user_id: UserId,
|
user_id: UserId,
|
||||||
|
channel: Option<ChannelId>,
|
||||||
query: &str,
|
query: &str,
|
||||||
loop_: bool,
|
loop_: bool,
|
||||||
) -> String {
|
) -> String {
|
||||||
let guild_id = guild.id;
|
let guild_id = guild.id;
|
||||||
|
|
||||||
let channel_to_join = guild
|
let channel_to_join = channel.or_else(|| {
|
||||||
|
guild
|
||||||
.voice_states
|
.voice_states
|
||||||
.get(&user_id)
|
.get(&user_id)
|
||||||
.and_then(|voice_state| voice_state.channel_id);
|
.and_then(|voice_state| voice_state.channel_id)
|
||||||
|
});
|
||||||
|
|
||||||
match channel_to_join {
|
match channel_to_join {
|
||||||
Some(user_channel) => {
|
Some(user_channel) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user