コード例 #1
0
        /// <summary>
        ///     Connect to a voice channel.
        /// </summary>
        /// <param name="voiceChannel">The voice channel to connect to.</param>
        /// <exception cref="InvalidPlayerException">Thrown if already connected to a voice channel.</exception>
        public async Task Join(IVoiceChannel voiceChannel)
        {
            if (_player != null)
            {
                throw new InvalidPlayerException("Already connected to a voice channel.");
            }
            if (!_lavaNode.IsConnected)
            {
                await _lavaNode.ConnectAsync();
            }

            _player = await _lavaNode.JoinAsync(voiceChannel);

            await _player.UpdateVolumeAsync(25);
        }
コード例 #2
0
        public async Task <string> JoinChannel(IGuild guild, IVoiceChannel voiceChannel, ITextChannel textChannel)
        {
            if (lavaNode.HasPlayer(guild))
            {
                return(await MoveAsync(guild, voiceChannel, textChannel));
            }
            LavaPlayer lp = await lavaNode.JoinAsync(voiceChannel, textChannel);

            if (lp == null)
            {
                return("Error joining voice channel.");
            }
            guildInfo.TryAdd(guild, new DJGuildInfo(voiceChannel));
            return($"Joined {voiceChannel.Name}.");
        }
コード例 #3
0
        /// <summary>Joins the voice channel the user is in and reacts to user message with 'okEmoji'.
        /// </summary>
        public async Task JoinAsync(SocketCommandContext context)
        {
            var guild       = context.Guild;
            var voiceState  = (IVoiceState)context.User;
            var textChannel = (ITextChannel)context.Channel;

            var okEmoji = new Emoji("👍");

            //If the user isn't connected to a voice channel
            if (voiceState == null)
            {
                await context.Channel.SendMessageAsync(
                    embed : CustomFormats.CreateErrorEmbed("You must be connected to a voice channel!"));

                return;
            }

            //If bot is already connected to a voice channel, do nothing and return
            if (_lavaNode.HasPlayer(guild))
            {
                return;
            }

            //If user is connected to a voice channel, and the bot isn't connected to it
            //Then try to join
            try
            {
                await _lavaNode.JoinAsync(voiceState.VoiceChannel, textChannel);

                await context.Message.AddReactionAsync(okEmoji);
            }
            catch (Exception ex)
            {
                await context.Channel.SendMessageAsync(embed : CustomFormats.CreateErrorEmbed(ex.Message));
            }
        }
コード例 #4
0
ファイル: MusicService.cs プロジェクト: DraxCodes/Xylox
        public async Task <IXyloxServiceResult> JoinAsync(ulong guildId, ulong voiceId, ulong textId)
        {
            var voiceChannel = GetDiscordChannel <IVoiceChannel>(voiceId);
            var textChannel  = GetDiscordChannel <ITextChannel>(textId);
            var guild        = GetGuild(guildId);

            if (_lavaNode.TryGetPlayer(guild, out var player))
            {
                return(new XyloxServiceResult {
                    Message = $"I am already joined to {player.VoiceChannel.Name}"
                });
            }


            await _lavaNode.JoinAsync(voiceChannel, textChannel);

            return(new XyloxServiceResult {
                Message = $"Joined {voiceChannel.Name}, bound to {textChannel.Name}"
            });
        }
コード例 #5
0
        public async Task JoinAsync()
        {
            await Context.Channel.TriggerTypingAsync();

            _logger.LogInformation("{username}#{discriminator} executed join on {server}/{channel}",
                                   Context.User.Username, Context.User.Discriminator, Context.Guild?.Name ?? "DM", Context.Channel.Name);

            if (!CheckIfLavaLinkIsEnabled())
            {
                return;
            }

            if (await ServerHelper.CheckIfContextIsDM(Context))
            {
                return;
            }

            if (_lavaNode.HasPlayer(Context.Guild))
            {
                await ReplyAsync("I'm already connected to a voice channel!");

                return;
            }

            var voiceState = Context.User as IVoiceState;

            if (!await CheckIfUserIsInVoiceChannel(voiceState))
            {
                return;
            }

            try
            {
                await _lavaNode.JoinAsync(voiceState.VoiceChannel, Context.Channel as ITextChannel);
                await ReplyAsync($"Joined {voiceState.VoiceChannel.Name}!");
            }
            catch (Exception exception)
            {
                await ReplyAsync(exception.Message);
            }
        }
コード例 #6
0
ファイル: Join.cs プロジェクト: kaguyabot/Kaguya
        public async Task Command([Remainder] string vcMatch = null)
        {
            LavaNode           node     = ConfigProperties.LavaNode;
            SocketVoiceChannel botCurVc = Context.Guild.CurrentUser.VoiceChannel;
            SocketVoiceChannel vc       = vcMatch == null
                ? (Context.User as SocketGuildUser).VoiceChannel
                : Context.Guild.VoiceChannels.First(x => x.Name.ToLower().Contains(vcMatch.ToLower()));

            if (node.HasPlayer(Context.Guild) && vc != null)
            {
                try
                {
                    await node.MoveChannelAsync(vc);
                }
                catch (Exception)
                {
                    await SendBasicErrorEmbedAsync($"It looks like I'm already connected to this voice channel " +
                                                   $"via the WebSocket. If I am not present in the voice channel, this " +
                                                   $"is due to an error. To fix this issue, join a new voice channel and " +
                                                   $"try the command again. This issue usually arises when I am manually " +
                                                   $"force-disconnected from the channel.");

                    return;
                }

                await SendBasicSuccessEmbedAsync(
                    $"{Context.User.Mention} Successfully moved to `{vc.Name}`.");
            }
            else
            {
                if (vc == botCurVc)
                {
                    await SendBasicErrorEmbedAsync($"I am already connected to this voice channel.");

                    return;
                }

                await node.JoinAsync(vc);
                await SendBasicSuccessEmbedAsync($"{Context.User.Mention} Successfully joined `{vc.Name}`.");
            }
        }
コード例 #7
0
        public async Task <bool> JoinAsync(SocketGuildUser user, ISocketMessageChannel chnl)
        {
            var channel = chnl as SocketGuildChannel;

            if (AdminUsers.ContainsValue(channel.Guild.Id))
            {
                if (user.VoiceChannel != channel.Guild.CurrentUser.VoiceChannel)
                {
                    RestUserMessage msg = await chnl.SendMessageAsync("", false, warnembed.IsUsing(channel.Guild.CurrentUser.VoiceChannel));
                    await DeleteTimeoutAsync(msg);

                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            if (user.VoiceChannel is null)
            {
                RestUserMessage msg = await chnl.SendMessageAsync("", false, warnembed.ShouldbeInVoice());
                await DeleteTimeoutAsync(msg);

                return(false);
            }
            await _lavaNode.JoinAsync(user.VoiceChannel, channel as ITextChannel);

            await Task.Delay(500);

            if (channel.Guild.CurrentUser.VoiceChannel == null)
            {
                await chnl.SendMessageAsync("", false, warnembed.NotEnoughPermission(_client));

                return(false);
            }
            AdminUsers.Add(user.Id, channel.Guild.Id);


            return(true);
        }
コード例 #8
0
        public static async Task <string> JoinAsync(IGuild guild, IVoiceState voiceState, ITextChannel channel)
        {
            if (_lavaNode.HasPlayer(guild))
            {
                return("ikiye mi bölüneyim ?");
            }
            if (voiceState.VoiceChannel is null)
            {
                return("bir yere gir babun");
            }

            try
            {
                await _lavaNode.JoinAsync(voiceState.VoiceChannel, channel);

                return($"{voiceState.VoiceChannel.Name} kanalına geldik sa");
            }
            catch (Exception ex)
            {
                return($"HATA\n{ex.Message}");
            }
        }
コード例 #9
0
        // Called when the bot joins the channel
        public async Task <Embed> ConnectAsync(IGuild guild, IVoiceState voiceState, ITextChannel textChannel)
        {
            if (_lavaNode.HasPlayer(guild))
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Join", "I'm already connected to a voice channel!"));
            }

            if (voiceState.VoiceChannel is null)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Join", "You must be connected to a voice channel!"));
            }

            try
            {
                await _lavaNode.JoinAsync(voiceState.VoiceChannel, textChannel);

                return(await EmbedHandler.CreateBasicEmbed("Music, Join", $"Joined {voiceState.VoiceChannel.Name}.", Color.Green));
            }
            catch (Exception ex)
            {
                return(await EmbedHandler.CreateErrorEmbed("Music, Join", ex.Message));
            }
        }
コード例 #10
0
ファイル: MusicModule.cs プロジェクト: goldentg/Nyme
        public async Task PlayAsync([Remainder] string query)
        {
            var voiceState = Context.User as IVoiceState;

            if (voiceState?.VoiceChannel == null)
            {
                await ReplyAsync("You must be connected to a voice channel!");

                return;
            }

            if (!_lavaNode.TryGetPlayer(Context.Guild, out var player)
                ) //Check if bot is connected to a voice channel in that guild and if not join new one
            {
                try
                {
                    await _lavaNode.JoinAsync(voiceState.VoiceChannel, Context.Channel as ITextChannel);

                    await Context.Channel.SendSuccessAsync("Success", $"Joined {voiceState.VoiceChannel.Name}");
                }
                catch (Exception exception)
                {
                    await Context.Channel.SendErrorAsync("Error", exception.Message);
                }
            }

            if (string.IsNullOrWhiteSpace(query)) //Check if nothing was entered
            {
                await Context.Channel.SendErrorAsync("Error", "Please provide search terms");

                return;
            }

            var players = _lavaNode.GetPlayer(Context.Guild);

            if (query.StartsWith("https://")) //Check if user entered link
            {
                var queries = query.Split(' ');
                foreach (var songQuery in queries)
                {
                    var searchResponse1 = await _lavaNode.SearchAsync(songQuery);

                    if (searchResponse1.LoadStatus == LoadStatus.LoadFailed ||
                        searchResponse1.LoadStatus == LoadStatus.NoMatches)
                    {
                        await Context.Channel.SendErrorAsync("Error", $"I could not find anything for `{songQuery}`");

                        return;
                    }


                    if (players.PlayerState == PlayerState.Playing || players.PlayerState == PlayerState.Paused)
                    {
                        if (!string.IsNullOrWhiteSpace(searchResponse1.Playlist.Name))
                        {
                            foreach (var track in searchResponse1.Tracks)
                            {
                                players.Queue.Enqueue(track);
                            }

                            var track1    = searchResponse1.Tracks[0];
                            var thumbnail = await track1.FetchArtworkAsync(); //get album cover for current song

                            await Context.Channel.Music("Enqued:",
                                                        $"Enqueued `{searchResponse1.Tracks.Count}` songs from the `{searchResponse1.Playlist.Name}` playlist",
                                                        thumbnail ??
                                                        "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fiynque%2Fios7-style%2F1024%2FMusic-icon.png&f=1&nofb=1");
                        }
                        else
                        {
                            var track     = searchResponse1.Tracks[0];
                            var thumbnail = await track.FetchArtworkAsync(); //get album cover for current song

                            players.Queue.Enqueue(track);
                            await ReplyAsync($"Enqueued: {track.Title}");

                            await Context.Channel.Music("Enqued:", $"Enqueued `{track.Title}`",
                                                        thumbnail ??
                                                        "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fiynque%2Fios7-style%2F1024%2FMusic-icon.png&f=1&nofb=1");
                        }
                    }
                    else
                    {
                        var track = searchResponse1.Tracks[0];
                        var thumb = await track.FetchArtworkAsync(); //get album cover for current song

                        if (!string.IsNullOrWhiteSpace(searchResponse1.Playlist.Name))
                        {
                            for (var i = 0; i < searchResponse1.Tracks.Count; i++)
                            {
                                if (i == 0)
                                {
                                    await players.PlayAsync(track);

                                    await Context.Channel.Music("Now Playing:", $"Now playing `{track.Title}`", thumb);
                                }
                                else
                                {
                                    players.Queue.Enqueue(searchResponse1.Tracks[i]);
                                }
                            }

                            var track1    = searchResponse1.Tracks[0];
                            var thumbnail = await track1.FetchArtworkAsync(); //get album cover for current song

                            await Context.Channel.Music("Enqued:",
                                                        $"Enqueued `{searchResponse1.Tracks.Count}` songs from the `{searchResponse1.Playlist.Name}` playlist",
                                                        thumbnail ??
                                                        "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fiynque%2Fios7-style%2F1024%2FMusic-icon.png&f=1&nofb=1");
                        }
                        else
                        {
                            var track1    = searchResponse1.Tracks[0];
                            var durSec    = track1.Duration.Seconds;
                            var durMin    = track1.Duration.Minutes;
                            var thumbnail = await track1.FetchArtworkAsync(); //get album cover for current song

                            await players.PlayAsync(track);

                            await Context.Channel.Music("Now Playing:",
                                                        $"**Now playing:** `{track.Title}`\n**Duration:** `{durMin}:{durSec}`", thumbnail);
                        }
                    }
                }
            }
            else //if query is not a url search youtube
            {
                var searchResponse = await _lavaNode.SearchYouTubeAsync(query);

                if (searchResponse.LoadStatus == LoadStatus.LoadFailed ||
                    searchResponse.LoadStatus == LoadStatus.NoMatches)
                {
                    await Context.Channel.SendErrorAsync("Error", $"I could not find anything for `{query}`");

                    //await ReplyAsync($"I wasn't able to find anything for `{query}`.");
                    return;
                }


                if (players.PlayerState == PlayerState.Playing || players.PlayerState == PlayerState.Paused)
                {
                    var track     = searchResponse.Tracks[0];
                    var thumbnail = await track.FetchArtworkAsync(); //get album cover for current song

                    var durSec = track.Duration.Seconds;
                    var durMin = track.Duration.Minutes;

                    players.Queue.Enqueue(track);
                    await Context.Channel.Music("Enqued:",
                                                $"**Song:** `{track.Title}`\n**Duration:** `{durMin}:{durSec}`",
                                                thumbnail ??
                                                "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fiynque%2Fios7-style%2F1024%2FMusic-icon.png&f=1&nofb=1");
                }
                else
                {
                    var track     = searchResponse.Tracks[0];
                    var thumbnail = await track.FetchArtworkAsync(); //get album cover for current song

                    var durSec = track.Duration.Seconds;
                    var durMin = track.Duration.Minutes;

                    await players.PlayAsync(track);

                    await Context.Channel.Music("Playing:",
                                                $"**Song:** `{track.Title}`\n**Duration:** `{durMin}:{durSec}`",
                                                thumbnail ??
                                                "https://external-content.duckduckgo.com/iu/?u=http%3A%2F%2Ficons.iconarchive.com%2Ficons%2Fiynque%2Fios7-style%2F1024%2FMusic-icon.png&f=1&nofb=1");
                }
            }
        }
コード例 #11
0
 public async Task ConnectAsync(SocketVoiceChannel voiceChannel, ITextChannel textChannel) => await _lavaNode.JoinAsync(voiceChannel, textChannel);
コード例 #12
0
ファイル: MusicService.cs プロジェクト: Haazelnut/HaazelBot
 public async Task JoinChannelAsync(SocketVoiceChannel voiceChannel, SocketTextChannel textChannel)
 => await _lavaNode.JoinAsync(voiceChannel, textChannel);
コード例 #13
0
 public async Task Connect(IVoiceChannel voiceChannel, ITextChannel messageChannel)
 {
     await _lavaNode.JoinAsync(voiceChannel, messageChannel);
 }
コード例 #14
0
        public async Task ConnectAsync(SocketVoiceChannel voiceChannel, SocketTextChannel textChannel)
        {
            await _lavaNode.JoinAsync(voiceChannel, textChannel);

            _player = _lavaNode.GetPlayer(voiceChannel.Guild);
        }
コード例 #15
0
        private async Task LavaNodeOnOnWebSocketClosed(WebSocketClosedEventArgs arg)
        {
            Console.WriteLine("Bot reconnected on voice channel");

            await _lavaNode.JoinAsync(_lavaNode.GetPlayer(_client.GetGuild(arg.GuildId)).VoiceChannel);
        }
コード例 #16
0
ファイル: Music.cs プロジェクト: Killklli/DiscordGuardianBot
        public static async System.Threading.Tasks.Task <bool> MusicCommands(SocketMessage message, CommandContext context, DiscordSocketClient client, LavaNode lava)
        {
            if (Validation.CheckCommand(message, "play"))
            {
                if ((message.Author as IVoiceState).VoiceChannel == null)
                {
                    DiscordFunctions.EmbedThis("Music", "You must first join a voice channel!", "red", context);
                    return(true);
                }


                var temp = client.GetGuild(context.Guild.Id).CurrentUser.VoiceState;
                if (temp != null && client.GetGuild(context.Guild.Id).CurrentUser.VoiceChannel != (message.Author as IVoiceState).VoiceChannel)
                {
                    DiscordFunctions.EmbedThis("Music", "I can't join another voice channel until I'm disconnected from another channel.", "red", context);
                    return(true);
                }

                SearchResponse search    = new SearchResponse();
                var            videoId   = string.Empty;
                var            timestamp = string.Empty;
                string         query     = message.Content.ToLower().Replace("!play ", "");
                if (query.ToLower().Contains("www.youtube.com/watch?v="))
                {
                    var uri     = new Uri(@query);
                    var queryid = HttpUtility.ParseQueryString(uri.Query);

                    if (queryid.AllKeys.Contains("v"))
                    {
                        videoId = queryid["v"];
                    }
                    else
                    {
                        videoId = uri.Segments.Last();
                    }
                    if (queryid.AllKeys.Contains("t"))
                    {
                        timestamp = queryid["t"];
                    }
                    if (timestamp != string.Empty)
                    {
                        videoId = videoId.Replace("&t=" + timestamp, "");
                    }
                    search = await lava.SearchYouTubeAsync(query.Replace("&t=" + timestamp, ""));
                }
                else
                {
                    search = await lava.SearchYouTubeAsync(query);
                }
                LavaTrack track = new LavaTrack();
                if (query.ToLower().Contains("www.youtube.com/watch?v="))
                {
                    bool found = false;
                    foreach (var vid in search.Tracks)
                    {
                        if (vid.Id.ToLower() == videoId)
                        {
                            track = vid;
                            found = true;
                            break;
                        }
                    }
                    if (found == false)
                    {
                        track = search.Tracks.FirstOrDefault();
                    }
                }
                else
                {
                    track = search.Tracks.FirstOrDefault();
                }

                var player = lava.HasPlayer(context.Guild)
                    ? lava.GetPlayer(context.Guild)
                    : await lava.JoinAsync((context.User as IVoiceState).VoiceChannel, (ITextChannel)message.Channel);

                if (player.PlayerState == PlayerState.Playing)
                {
                    player.Queue.Enqueue(track);
                    DiscordFunctions.EmbedThis("Music", "Enqeued " + track.Title, "orange", context);
                }
                else
                {
                    await player.PlayAsync(track);

                    try
                    {
                        if (timestamp != string.Empty)
                        {
                            if (timestamp.ToLower().Contains("s"))
                            {
                                timestamp = timestamp.ToLower().Replace("s", "");
                            }
                            await player.SeekAsync(TimeSpan.FromSeconds(Convert.ToDouble(timestamp)));
                        }
                    }
                    catch { }
                    DiscordFunctions.EmbedThis("Music", "Playing " + track.Title, "green", context);
                }
                return(true);
            }
            else if (Validation.CheckCommand(message, "skip"))
            {
                var _player = lava.GetPlayer(context.Guild);
                if (_player is null || _player.Queue.Count is 0)
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing in the queue", "orange", context);
                    return(true);
                }

                var oldTrack = _player.Track;
                await _player.SkipAsync();

                DiscordFunctions.EmbedThis("Music", "Skipped: " + oldTrack.Title + "\nNow Playing: " + _player.Track.Title, "orange", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "stop"))
            {
                var _player = lava.GetPlayer(context.Guild);
                if (_player == null)
                {
                    return(true);
                }

                await _player.StopAsync();

                DiscordFunctions.EmbedThis("Music", "Stopped player", "orange", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "volume"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (string.IsNullOrWhiteSpace(message.Content.Replace("!volume", "")))
                {
                    DiscordFunctions.EmbedThis("Music", "Please use a number between 2- 150", "orange", context);
                    return(true);
                }
                var vol = Convert.ToUInt16(message.Content.Replace("!volume", "").Trim());
                if (vol > 150 || vol <= 2)
                {
                    DiscordFunctions.EmbedThis("Music", "Please use a number between 2- 150", "orange", context);
                    return(true);
                }

                await _player.UpdateVolumeAsync(vol);

                DiscordFunctions.EmbedThis("Music", "Volume set to: " + vol.ToString(), "green", context);
                return(true);
            }
            else if (Validation.CheckCommand(message, "pause"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (_player.PlayerState != PlayerState.Paused)
                {
                    await _player.PauseAsync();

                    DiscordFunctions.EmbedThis("Music", "Player is Paused", "orange", context);
                    return(true);
                }
                else
                {
                    await _player.ResumeAsync();

                    DiscordFunctions.EmbedThis("Music", "Playback Resumed", "green", context);
                    return(true);
                }
            }
            else if (Validation.CheckCommand(message, "resume"))
            {
                LavaPlayer _player;
                try
                {
                    _player = lava.GetPlayer(context.Guild);
                }
                catch
                {
                    DiscordFunctions.EmbedThis("Music", "Nothing is playing", "orange", context);
                    return(true);
                }
                if (_player.PlayerState != PlayerState.Paused)
                {
                    await _player.ResumeAsync();

                    DiscordFunctions.EmbedThis("Music", "Playback Resumed", "green", context);
                    return(true);
                }
                else
                {
                    DiscordFunctions.EmbedThis("Music", "Playback is not paused", "orange", context);
                    return(true);
                }
            }
            else if (Validation.CheckCommand(message, "join"))
            {
                var user = context.User as SocketGuildUser;
                if (user.VoiceChannel is null)
                {
                    DiscordFunctions.EmbedThis("Music", "You need to connect to a voice channel", "red", context);
                    return(true);
                }
                else
                {
                    LavaPlayer _player;
                    try
                    {
                        _player = lava.GetPlayer(context.Guild);
                        DiscordFunctions.EmbedThis("Music", "Bot is already in a channel", "red", context);
                        return(true);
                    }
                    catch
                    {
                        await lava.JoinAsync((context.User as IVoiceState).VoiceChannel, (ITextChannel)message.Channel);

                        return(true);
                    }
                }
            }
            else if (Validation.CheckCommand(message, "leave"))
            {
                var user = context.User as SocketGuildUser;
                if (user.VoiceChannel is null)
                {
                    DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                    return(true);
                }
                else
                {
                    LavaPlayer _player;
                    try
                    {
                        _player = lava.GetPlayer(context.Guild);
                    }
                    catch
                    {
                        DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                        return(true);
                    }
                    if (_player.VoiceChannel == user.VoiceChannel)
                    {
                        await lava.LeaveAsync((context.User as IVoiceState).VoiceChannel);
                    }
                    else
                    {
                        DiscordFunctions.EmbedThis("Music", "Please join the channel the bot is in to make it leave", "red", context);
                        return(true);
                    }
                }
            }
            return(false);
        }
コード例 #17
0
ファイル: Search.cs プロジェクト: kaguyabot/Kaguya
        /// <summary>
        ///     Searches the specified <see cref="SearchProvider" /> for the provided <see cref="query" />.
        ///     This method also adds the song to the guild's player queue and will even join the user's voice
        ///     channel automatically.
        /// </summary>
        /// <param name="context"></param>
        /// <param name="query">The song to search for, user input.</param>
        /// <param name="playFirst"></param>
        /// <param name="provider"></param>
        /// <returns></returns>
        public async Task <ReactionCallbackData> SearchAndPlayAsync(ShardedCommandContext context,
                                                                    string query,
                                                                    bool playFirst          = false,
                                                                    SearchProvider provider = SearchProvider.YOU_TUBE)
        {
            User user = await DatabaseQueries.GetOrCreateUserAsync(context.User.Id);

            Server server = await DatabaseQueries.GetOrCreateServerAsync(context.Guild.Id);

            LavaNode           node  = ConfigProperties.LavaNode;
            SocketVoiceChannel curVc = (context.User as SocketGuildUser).VoiceChannel;

            await ConsoleLogger.LogAsync($"Found node and voice channel for guild {context.Guild.Id}.", LogLvl.TRACE);

            if (curVc == null)
            {
                await context.Channel.SendMessageAsync($"{context.User.Mention} You must be in a voice " +
                                                       "channel to use this command.");

                await ConsoleLogger.LogAsync("User was not in voice channel, cancelling music search operation.", LogLvl.TRACE);

                return(null);
            }

            SearchResponse result = provider switch
            {
                SearchProvider.YOU_TUBE => await node.SearchYouTubeAsync(query),
                SearchProvider.SOUNDCLOUD => await node.SearchSoundCloudAsync(query),
                _ => await node.SearchAsync(query)
            };

            if (provider == SearchProvider.TWITCH)
            {
                const string PROVIDER_URL = "www.twitch.tv";
                string       errorString  = "Your search returned no results. Ensure you are only " +
                                            "typing the name of the streamer who you want to watch or a direct link to their stream.\n\n" +
                                            "Note: The streamer must be live for this feature to work.";

                if (!query.ToLower().Contains(PROVIDER_URL))
                {
                    result = await node.SearchAsync($"https://{PROVIDER_URL}/{query}");

                    if (result.Tracks.Count == 0)
                    {
                        await context.Channel.SendBasicErrorEmbedAsync(errorString);

                        await ConsoleLogger.LogAsync($"No livestream found for search {query} in guild {context.Guild.Id}.", LogLvl.TRACE);

                        return(null);
                    }
                }
                else
                {
                    if ((await node.SearchAsync($"https://{PROVIDER_URL}/{query.Split('\\').Last()}")).Tracks.Count == 0 &&
                        (await node.SearchAsync(query)).Tracks.Count == 0)
                    {
                        await context.Channel.SendBasicErrorEmbedAsync(errorString);

                        await ConsoleLogger.LogAsync($"No livestream found for search {query} in guild {context.Guild.Id}.", LogLvl.TRACE);

                        return(null);
                    }
                }
            }

            var tracks = new List <LavaTrack>();

            if (user.IsPremium || server.IsPremium)
            {
                if (result.Tracks.Any())
                {
                    tracks.AddRange(result.Tracks);
                }
            }
            else
            {
                // Limit track duration to 10 minutes for non-premium servers/users.
                if (result.Tracks.Any())
                {
                    tracks.AddRange(result.Tracks.Where(x => x.Duration.TotalMinutes < 10).ToList());
                }
            }

            if (!tracks.Any())
            {
                string suppString = user.IsPremium
                    ? ""
                    : "If you are " +
                                    $"not a [Kaguya Premium Subscriber]({ConfigProperties.KAGUYA_STORE_URL}), " +
                                    "you are only limited to playing songs less than `10 minutes` in duration.";

                await context.Channel.SendBasicErrorEmbedAsync($"Your requested search returned no results. {suppString}");

                await ConsoleLogger.LogAsync("Search request returned no usable " +
                                             $"results in guild {Context.Guild.Id} for query {query}", LogLvl.TRACE);
            }

            var fields    = new List <EmbedFieldBuilder>();
            var callbacks = new List <(IEmote, Func <SocketCommandContext, SocketReaction, Task>)>();

            Emoji[] emojiNums = GlobalProperties.EmojisOneThroughNine();

            LavaPlayer player = node.HasPlayer(context.Guild)
                ? node.GetPlayer(context.Guild)
                : await node.JoinAsync(curVc);

            await ConsoleLogger.LogAsync($"Player found for guild {context.Guild.Id}. Connected to voice channel.", LogLvl.TRACE);

            #region If the track is a livestream:
            if (tracks.Any(x => x.IsStream))
            {
                LavaTrack trackSel   = tracks.First(x => x.IsStream); // Gathers the first stream from the collection.
                string    twitchName = (await ConfigProperties.TwitchApi.V5.Users.GetUserByNameAsync(trackSel.Author)).Matches[0].DisplayName;
                string    playString = player.PlayerState == PlayerState.Playing
                    ? $"Queued stream into position {player.Queue.Count}."
                    : $"Now playing `{twitchName}`'s stream.";

                if (player.PlayerState == PlayerState.Playing)
                {
                    try
                    {
                        player.Queue.Enqueue(trackSel);
                        await ConsoleLogger.LogAsync($"Enqueued livestream {trackSel.Title} in guild {context.Guild.Id}",
                                                     LogLvl.TRACE);
                    }
                    catch (Exception e)
                    {
                        await ConsoleLogger.LogAsync("An exception was thrown when trying to enqueue the livestream " +
                                                     $"{trackSel.Title} in guild {Context.Guild.Id}.\n" +
                                                     $"Exception Message: {e.Message}\n" +
                                                     $"Stack Trace: {e.StackTrace}", LogLvl.WARN);
                    }
                }
                else
                {
                    try
                    {
                        await player.PlayAsync(trackSel);

                        await ConsoleLogger.LogAsync($"Playing livestream {trackSel.Title} in guild {context.Guild.Id}",
                                                     LogLvl.TRACE);
                    }
                    catch (Exception e)
                    {
                        await ConsoleLogger.LogAsync("An exception was thrown when trying to play track " +
                                                     $"{trackSel.Title} in guild {Context.Guild.Id}.\n" +
                                                     $"Exception Message: {e.Message}\n" +
                                                     $"Stack Trace: {e.StackTrace}", LogLvl.WARN);
                    }
                }

                var field = new EmbedFieldBuilder
                {
                    Name  = $"`{twitchName}`'s Stream",
                    Value = $"{playString}\n" // We get rid of backticks for formatting.
                };

                var embed = new KaguyaEmbedBuilder
                {
                    Fields = new List <EmbedFieldBuilder>
                    {
                        field
                    }
                };

                await context.Channel.SendEmbedAsync(embed);

                return(null);
            }
            #endregion

            #region If we have chosen to only play the default track (via $play).
            if (playFirst && tracks.Any())
            {
                LavaTrack trackSel = tracks[0];
                var       field    = new EmbedFieldBuilder
                {
                    Name  = "Track #1.",
                    Value = $"Title: `{trackSel.Title.Replace("`", "")}`\n" + // We get rid of backticks for formatting.
                            $"Duration: `{trackSel.Duration.Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 3)}`\n" +
                            $"Uploader: `{trackSel.Author}`"
                };

                string playString = player.PlayerState == PlayerState.Playing && !player.Track.IsStream
                    ? $"Queued track #1 into position {player.Queue.Count + 1}."
                    : "Now playing track #1.";

                if (player.PlayerState == PlayerState.Playing)
                {
                    if (player.Queue.Count() == 50 && !server.IsPremium)
                    {
                        await ConsoleLogger.LogAsync($"Queue is full in {context.Guild.Id}, sending error.", LogLvl.TRACE);
                        await SendBasicErrorEmbedAsync("Your queue is full! `50 songs` is the maximum " +
                                                       $"for non [Kaguya Premium]({ConfigProperties.KAGUYA_STORE_URL}) " +
                                                       "servers.");
                    }
                    else
                    {
                        player.Queue.Enqueue(trackSel);
                        await ConsoleLogger.LogAsync($"Enqueued track {trackSel.Title} in guild {context.Guild.Id}.", LogLvl.TRACE);

                        if (player.Track.IsStream)
                        {
                            await player.SkipAsync();

                            await ConsoleLogger.LogAsync($"Skipped livestream to play incoming track in guild {context.Guild.Id}.", LogLvl.TRACE);
                        }
                    }
                }
                else
                {
                    try
                    {
                        await player.PlayAsync(trackSel);

                        await ConsoleLogger.LogAsync($"Playing track {trackSel.Title} in guild {context.Guild.Id}",
                                                     LogLvl.TRACE);
                    }
                    catch (Exception e)
                    {
                        await ConsoleLogger.LogAsync("An exception was thrown when trying to play track " +
                                                     $"{trackSel.Title} in guild {Context.Guild.Id}.\n" +
                                                     $"Exception Message: {e.Message}\n" +
                                                     $"Stack Trace: {e.StackTrace}", LogLvl.WARN);
                    }
                }

                if (player.Volume == 0 && player.PlayerState == PlayerState.Playing)
                {
                    await player.UpdateVolumeAsync(75); // Sets the volume back to default if it is muted.

                    await ConsoleLogger.LogAsync($"Automatically set player volume to 75 in guild {context.Guild.Id}.", LogLvl.TRACE);
                }

                var embed = new KaguyaEmbedBuilder
                {
                    Title        = $"Kaguya Music {Centvrio.Emoji.Music.Notes}",
                    Description  = playString,
                    ThumbnailUrl = await trackSel.FetchArtworkAsync(),
                    Fields       = new List <EmbedFieldBuilder>
                    {
                        field
                    }
                };

                await SendEmbedAsync(embed, context);

                return(null);
            }
            #endregion

            int h = tracks.Count;
            for (int i = 0; i < (h < 7 ? h : 7); i++)
            {
                int       i1       = i;
                LavaTrack trackSel = tracks[i];
                var       field    = new EmbedFieldBuilder
                {
                    Name  = $"Track {i1 + 1}.",
                    Value = $"Title: `{trackSel.Title.Replace("`", "")}`\n" + // We get rid of backticks for formatting.
                            $"Duration: `{trackSel.Duration.Humanize(minUnit: TimeUnit.Second, maxUnit: TimeUnit.Hour, precision: 3)}`\n" +
                            $"Uploader: `{trackSel.Author}`"
                };

                fields.Add(field);
                callbacks.Add((emojiNums[i], async(c, r) =>
                {
                    string playString = player.PlayerState == PlayerState.Playing && !player.Track.IsStream
                                ? $"Queued track #{i1 + 1} into position {player.Queue.Count + 1}."
                                : $"Now playing track #{i1 + 1}.";

                    if (player.PlayerState == PlayerState.Playing)
                    {
                        if (player.Queue.Count() == 50 && !server.IsPremium)
                        {
                            await ConsoleLogger.LogAsync($"Queue was full in guild {context.Guild.Id}. Sending error message.", LogLvl.TRACE);
                            await SendBasicErrorEmbedAsync("Your queue is full! `50 songs` is the maximum " +
                                                           $"for non [Kaguya Premium]({ConfigProperties.KAGUYA_STORE_URL}) " +
                                                           "servers.");

                            return;
                        }

                        player.Queue.Enqueue(trackSel);
                        await ConsoleLogger.LogAsync($"Enqueued track {trackSel} in guild {context.Guild.Id}", LogLvl.TRACE);

                        if (player.Track.IsStream)
                        {
                            await player.SkipAsync();
                            await ConsoleLogger.LogAsync("Automatically skipped livestream to play" +
                                                         $" incoming track in guild {context.Guild.Id}", LogLvl.TRACE);
                        }
                    }
                    else
                    {
                        try
                        {
                            await player.PlayAsync(trackSel);
                            await ConsoleLogger.LogAsync($"Playing track {trackSel.Title} in guild {context.Guild.Id}",
                                                         LogLvl.TRACE);
                        }
                        catch (Exception e)
                        {
                            await ConsoleLogger.LogAsync("An exception was thrown when trying to play track " +
                                                         $"{trackSel.Title} in guild {Context.Guild.Id}.\n" +
                                                         $"Exception Message: {e.Message}\n" +
                                                         $"Stack Trace: {e.StackTrace}", LogLvl.WARN);
                        }
                    }

                    if (player.Volume == 0 && player.PlayerState == PlayerState.Playing)
                    {
                        await player.UpdateVolumeAsync(75);         // Sets the volume back to default if it is muted.
                        await ConsoleLogger.LogAsync($"Automatically set volume to 75 in guild {context.Guild.Id}", LogLvl.TRACE);
                    }

                    var embed = new KaguyaEmbedBuilder
                    {
                        Title = $"Kaguya Music {Centvrio.Emoji.Music.Notes}",
                        Description = playString,
                        ThumbnailUrl = await trackSel.FetchArtworkAsync(),
                        Fields = new List <EmbedFieldBuilder>
                        {
                            field
                        }
                    };

                    await SendEmbedAsync(embed);
                }
                               ));
            }

            callbacks.Add((GlobalProperties.NoEntryEmoji(), async(c, r) =>
            {
                await c.Message.DeleteAsync();
                await r.Message.Value.DeleteAsync();
            }));

            string s = tracks.Count == 1 ? "" : "s";
            var    songDisplayEmbed = new KaguyaEmbedBuilder
            {
                Title       = "Kaguya Music Search Results",
                Description = $" I found {tracks.Count} track{s} from {provider}, " +
                              $"{(tracks.Count > 5 ? "but here are the top 5" : "here they are")}. " +
                              "Please select a track to play.",
                Fields = fields
            };

            var data = new ReactionCallbackData("", songDisplayEmbed.Build(), false, false,
                                                TimeSpan.FromSeconds(60));

            data.SetCallbacks(callbacks);

            return(data);
        }
    }