diff options
| author | Derrick Lee <[email protected]> | 2018-05-31 15:51:02 -0700 |
|---|---|---|
| committer | Alex M. M <[email protected]> | 2018-06-01 00:51:02 +0200 |
| commit | a80aab264b3d81c2457eb6bef755a5b0d1a88e4b (patch) | |
| tree | 5a551eb914d6b5a483cabcdc27f40cd286c3fe9f /examples/06_voice | |
| parent | Add methods to check whether `Message` is mentioning `User` (#323) (diff) | |
| download | serenity-a80aab264b3d81c2457eb6bef755a5b0d1a88e4b.tar.xz serenity-a80aab264b3d81c2457eb6bef755a5b0d1a88e4b.zip | |
Update the voice example to join the channel the user is in (#325)
Diffstat (limited to 'examples/06_voice')
| -rw-r--r-- | examples/06_voice/src/main.rs | 29 |
1 files changed, 18 insertions, 11 deletions
diff --git a/examples/06_voice/src/main.rs b/examples/06_voice/src/main.rs index 2bc3519..c2681c5 100644 --- a/examples/06_voice/src/main.rs +++ b/examples/06_voice/src/main.rs @@ -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`. // @@ -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(); |