Skip to content

Commit

Permalink
Update the voice example to join the channel the user is in (#325)
Browse files Browse the repository at this point in the history
  • Loading branch information
drklee3 authored and arqunis committed May 31, 2018
1 parent 1162e68 commit a80aab2
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions examples/06_voice/src/main.rs
Expand Up @@ -19,7 +19,6 @@ use serenity::client::{CACHE, Client, Context, EventHandler};
use serenity::framework::StandardFramework;
use serenity::model::channel::Message;
use serenity::model::gateway::Ready;
use serenity::model::id::ChannelId;
use serenity::model::misc::Mentionable;
// Import the `Context` from the client and `parking_lot`'s `Mutex`.
//
Expand Down Expand Up @@ -109,23 +108,31 @@ command!(deafen(ctx, msg) {
}
});

command!(join(ctx, msg, args) {
let connect_to = match args.single::<u64>() {
Ok(id) => ChannelId(id),
Err(_) => {
check_msg(msg.reply("Requires a valid voice channel ID be given"));
command!(join(ctx, msg) {
let guild = match msg.guild() {
Some(guild) => guild,
None => {
check_msg(msg.channel_id.say("Groups and DMs not supported"));

return Ok(());
},
}
};

let guild_id = match CACHE.read().guild_channel(msg.channel_id) {
Some(channel) => channel.read().guild_id,
let guild_id = guild.read().id;

let channel_id = guild
.read()
.voice_states.get(&msg.author.id)
.and_then(|voice_state| voice_state.channel_id);


let connect_to = match channel_id {
Some(channel) => channel,
None => {
check_msg(msg.channel_id.say("Groups and DMs not supported"));
check_msg(msg.reply("Not in a voice channel"));

return Ok(());
},
}
};

let mut manager_lock = ctx.data.lock().get::<VoiceManager>().cloned().unwrap();
Expand Down

0 comments on commit a80aab2

Please sign in to comment.