Ejemplo n.º 1
0
        public async Task YouTubeCmd([Remainder] string query)
        {
            LavalinkPlayer player = _lavaManager.GetPlayer(Context.Guild.Id) ?? await _lavaManager.JoinAsync((Context.User as IVoiceState).VoiceChannel);

            LoadTracksResponse r = await _lavaManager.GetTracksAsync($"ytsearch:{query}");

            LavalinkTrack tr = r.Tracks.First();

            await player.PlayAsync(tr);

            await ReplyAsync("", embed : GetTrackInfoEmbed(tr, Context.User));
        }
Ejemplo n.º 2
0
        public static async Task PlayAsync(SocketCommandContext context, string song, int choose, YoutubeVideo video = null)
        {
            // Create used objects
            SocketGuild           guild        = context.Guild;
            SocketUserMessage     message      = context.Message;
            IVoiceChannel         voiceChannel = (context.User as IVoiceState).VoiceChannel;
            ISocketMessageChannel channel      = context.Channel;
            Utilities             utilities    = new Utilities(guild);

            // Checking if voice channel is null (and sending an error message)
            // If not, creating or getting a lavalink player
            // Checking if a given string is empty (if true, and there is a song in queue that is stopped, resuming it
            if (await VoiceChannelIsNull(channel, voiceChannel, utilities) is true)
            {
                return;
            }
            LavalinkPlayer player = lavalinkManager.GetPlayer(guild.Id) ?? await lavalinkManager.JoinAsync(voiceChannel);

            var audioQueue = AudioQueues.GetAudioQueue(guild);

            if (await SongIsEmpty(channel, utilities, player, audioQueue, song) is true)
            {
                return;
            }

            LoadTracksResponse response = await lavalinkManager.GetTracksAsync(song);

            LavalinkTrack track = response.Tracks.First();

            // Maximum songs in queue is 50
            if (await QueueIsFull(channel, utilities, audioQueue.Queue.Count) is true)
            {
                return;
            }

            // Adding a track to queue
            audioQueue.Queue = AudioQueues.GetOrCreateGuildQueue(track, audioQueue);

            // A check if a song is first in the queue, or if it's been added
            string songAlert = "PLAY_ADDED_SONG";

            if (await SongIsFirst(player, audioQueue, track, video, context, songAlert, choose) is false)
            {
                return;
            }
            // If a user gives a link to a youtube video, we don't need to send song info
            if (choose != -1)
            {
                await SongInfo(channel, message, video, choose, songAlert);
            }
        }