Example #1
0
        public async Task QueueSong(string query, SocketUser usr, IMessageChannel channel, IGuild guild, SocketUserMessage usrmsg)
        {
            if ((usr as IVoiceState).VoiceChannel == null)
            {
                await channel.SendMessageAsync(usr.Mention + " você não está conectado em nenhum canal de voz");

                return;
            }
            Video video = YTVideoOperation.YoutubeSearch(query);

            if (video == null)
            {
                var embedL = new EmbedBuilder()
                             .WithColor(new Color(240, 230, 231))
                             .WithDescription("Nenhum resultado encontrado para: " + query);
                await channel.SendMessageAsync("", false, embedL);

                return;
            }

            //Attempts to get the audio URI either by YoutubeExplode or youtube-dl
            //First attempt is with YoutubeExplode
            string uri = YTVideoOperation.GetVideoURIExplode(video.Id).Result;


            if (uri == null)
            {
                uri = YTVideoOperation.GetVideoAudioURI("https://www.youtube.com/watch?v=" + video.Id);
            }

            YTSong song = new YTSong(video, uri, query, SongOrder(), usr);

            mp.Enqueue(song);
            var embedQueue = new EmbedBuilder()
                             .WithColor(new Color(240, 230, 231))
                             .WithTitle("#" + song.Order + "  " + song.Title)
                             .WithDescription("Busca: " + query)
                             .WithUrl(song.Url)
                             .WithImageUrl(song.DefaultThumbnailUrl)
                             .WithFooter(new EmbedFooterBuilder().WithText(song.RequestAuthor.Username + " | " + song.Duration));

            var msg = await channel.SendMessageAsync("", false, embedQueue);

            await Task.Delay(6000);

            await usrmsg.DeleteAsync().ConfigureAwait(false);

            await msg.DeleteAsync().ConfigureAwait(false);
        }