예제 #1
0
        public async Task <ActionResult> Command_TrackAsync(
            [Name("Track Name")]
            [Description("The track to search for.")]
            [Remainder]
            [DefaultValueDescription("The track that you're currently listening to.")]
            string trackQuery = null)
        {
            SpotifyTrack track;

            if (trackQuery != null)
            {
                var tracks = await _spotify.SearchAsync(trackQuery, SearchType.Track).ConfigureAwait(false);

                track = tracks.Tracks.Items.FirstOrDefault();
            }
            else
            {
                if (!(Context.Invoker.Activity is SpotifyGame spot))
                {
                    return(BadRequest("You didn't supply a track, and you're not currently listening to anything!"));
                }

                track = await _spotify.GetTrackAsync(spot.TrackId).ConfigureAwait(false);
            }

            if (track == null)
            {
                return(BadRequest("Cannot find a track by that name."));
            }
            return(Ok(CreateTrackEmbed(track)));
        }