fix Bot throwing an error when tryimg to autoplay tracks from non youtube sources
This commit is contained in:
parent
fcd376bdcb
commit
47bffbff7f
@ -203,7 +203,6 @@ namespace TomatenMusic.Music
|
|||||||
public async override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
|
public async override Task OnTrackEndAsync(TrackEndEventArgs eventArgs)
|
||||||
{
|
{
|
||||||
DisconnectOnStop = false;
|
DisconnectOnStop = false;
|
||||||
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
|
|
||||||
var oldTrack = CurrentTrack;
|
var oldTrack = CurrentTrack;
|
||||||
|
|
||||||
if (eventArgs.Reason != TrackEndReason.Finished)
|
if (eventArgs.Reason != TrackEndReason.Finished)
|
||||||
@ -226,12 +225,8 @@ namespace TomatenMusic.Music
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
TomatenMusicTrack newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
|
|
||||||
_logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}");
|
|
||||||
await base.OnTrackEndAsync(eventArgs);
|
await base.OnTrackEndAsync(eventArgs);
|
||||||
PlayerQueue.LastTrack = newTrack;
|
_ = OnAutoPlay(oldTrack);
|
||||||
await newTrack.Play(this);
|
|
||||||
QueuePrompt.UpdateFor(GuildId);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -239,6 +234,21 @@ namespace TomatenMusic.Music
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task OnAutoPlay(LavalinkTrack oldTrack)
|
||||||
|
{
|
||||||
|
YoutubeService youtube = TomatenMusicBot.ServiceProvider.GetRequiredService<YoutubeService>();
|
||||||
|
|
||||||
|
TomatenMusicTrack newTrack;
|
||||||
|
if (oldTrack.Source != "YouTube" )
|
||||||
|
newTrack = await youtube.GetRelatedTrackAsync(PlayerQueue.PlayedTracks.First(x => x.Source == "YouTube").TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
|
||||||
|
else
|
||||||
|
newTrack = await youtube.GetRelatedTrackAsync(oldTrack.TrackIdentifier, PlayerQueue.PlayedTracks.Take(5).ToList().ConvertAll(x => x.TrackIdentifier));
|
||||||
|
_logger.LogInformation($"Autoplaying for track {oldTrack.TrackIdentifier} with Track {newTrack.TrackIdentifier}");
|
||||||
|
PlayerQueue.LastTrack = newTrack;
|
||||||
|
await newTrack.Play(this);
|
||||||
|
QueuePrompt.UpdateFor(GuildId);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<DiscordChannel> GetChannelAsync()
|
public async Task<DiscordChannel> GetChannelAsync()
|
||||||
{
|
{
|
||||||
EnsureConnected();
|
EnsureConnected();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user