Skip to content

Commit

Permalink
fix: Fix DSharpPlus sample race-condition
Browse files Browse the repository at this point in the history
  • Loading branch information
angelobreuer committed Jan 21, 2024
1 parent d5c5c6f commit 2a3efda
Showing 1 changed file with 5 additions and 14 deletions.
19 changes: 5 additions & 14 deletions samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Threading;
using System.Threading.Tasks;
using DSharpPlus;
using DSharpPlus.EventArgs;
using Lavalink4NET;
using Lavalink4NET.Extensions;
using Lavalink4NET.Players;
Expand All @@ -15,7 +14,7 @@
// DSharpPlus
builder.Services.AddHostedService<ApplicationHost>();
builder.Services.AddSingleton<DiscordClient>();
builder.Services.AddSingleton(new DiscordConfiguration { Token = "", }); // Put token here
builder.Services.AddSingleton(new DiscordConfiguration { Token = "MTE0MjkyMzgyNzU5MzA5NzI0Nw.GEVyUW.0MyX23SfZM9HrRiSWYJOkh-71CDFsgXfS1ul7Q", }); // Put token here

This comment has been minimized.

Copy link
@angelobreuer

angelobreuer Jan 21, 2024

Author Owner

No worries, it is revoked


// Lavalink
builder.Services.AddLavalink();
Expand Down Expand Up @@ -46,25 +45,17 @@ await _discordClient
.ConnectAsync()
.ConfigureAwait(false);

var readyTaskCompletionSource = new TaskCompletionSource();

Task SetResult(DiscordClient client, ReadyEventArgs eventArgs)
{
readyTaskCompletionSource.TrySetResult();
return Task.CompletedTask;
}

_discordClient.Ready += SetResult;
await readyTaskCompletionSource.Task.ConfigureAwait(false);
_discordClient.Ready -= SetResult;
await _audioService
.WaitForReadyAsync(stoppingToken)
.ConfigureAwait(false);

var playerOptions = new LavalinkPlayerOptions
{
InitialTrack = new TrackReference("https://www.youtube.com/watch?v=dQw4w9WgXcQ"),
};

await _audioService.Players
.JoinAsync(0, 0, playerOptions, stoppingToken) // Ids
.JoinAsync(1023169934819328031, 1023169936790663208, playerOptions, stoppingToken) // Ids
.ConfigureAwait(false);
}
}

0 comments on commit 2a3efda

Please sign in to comment.