コード例 #1
0
        public async Task Play()
        {
            // check whether VNext is enabled
            var vnext = ctx.Client.GetVoiceNext();
            if (vnext == null)
            {
                // not enabled
                await ctx.RespondAsync("VNext is not enabled or configured.");
                return;
            }

            // check whether we aren't already connected
            vnc = vnext.GetConnection(ctx.Guild);
            if (vnc == null)
            {
                // already connected
                await ctx.RespondAsync("Not connected in this guild.");
                return;
            }

            // play
            if (vnc.IsPlaying)
                await ctx.RespondAsync($"Added to Queue: `{NextQueueSong.Name}` | Requested by: {UserExtension.GetUsername(ctx.Message.Author)}");
            else
            {

                Exception exc = null;
                await vnc.SendSpeakingAsync(true);
                try
                {
                    filename = qs.Peek().URL; //Set song filename

                    transmitStream = vnc.GetTransmitStream(); //Get Voice transmission stream

                    // check if music input is url and if it is not check if file exists
                    if (!WolfBot.Tools.Network.StringNetworkTools.IsURL(filename))
                    {
                        if (!File.Exists(filename))
                        {
                            // file does not exist
                            await ctx.RespondAsync($"File `{filename}` does not exist.");
                            //Remove the invalid file from the queue
                            qs.Dequeue();
                        }
                    }
                    else
                    {
                        //If the song is not skipped play it
                        if (!qs.Peek().isSkipped)
                        {
                            //await ctx.Message.RespondAsync($"Now Playing `{qs.Peek().Name}` | Requested by: {UserExtension.GetUsername(ctx.Message.Author)}");
                            playingSong = qs.Peek(); //Add playing song

                            //Show song info
                            try
                            {
                                new SongEmbedBuilder(this);
                            }
                            catch
                            {
                                await ctx.RespondAsync("`Resource not found`");
                            }

                            //Play the damm song :)
                            PlayInternal(filename);
                        }
                        else
                        {
                            await ctx.Message.RespondAsync($"Song: `{qs.Peek().Name}` | Requested by: {UserExtension.GetUsername(ctx.Message.Author)} is skipped");
                        }
                    }

                }
                catch (System.InvalidOperationException ext) 
                { 
                    if (ext.Message == "Queue empty")
                    {
                        //Playback is probably over
                    }
                }
                catch (Exception ex) { exc = ex; }
                finally
                {
                    await vnc.SendSpeakingAsync(false);
                    await MusicPlayBackFinished(vnc, "next-song");
                }

                if (exc != null)
                    await ctx.RespondAsync($"An exception occured during playback: `{exc.GetType()}: {exc.Message}`");
            }
        }