From 2a3efda01e9343df803b05e75d99e0793564419d Mon Sep 17 00:00:00 2001 From: Angelo Breuer Date: Sun, 21 Jan 2024 16:14:09 +0100 Subject: [PATCH] fix: Fix DSharpPlus sample race-condition --- .../Program.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs b/samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs index 265ab916..f039c898 100644 --- a/samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs +++ b/samples/Lavalink4NET.DSharpPlus.ExampleBot/Program.cs @@ -2,7 +2,6 @@ using System.Threading; using System.Threading.Tasks; using DSharpPlus; -using DSharpPlus.EventArgs; using Lavalink4NET; using Lavalink4NET.Extensions; using Lavalink4NET.Players; @@ -15,7 +14,7 @@ // DSharpPlus builder.Services.AddHostedService(); builder.Services.AddSingleton(); -builder.Services.AddSingleton(new DiscordConfiguration { Token = "", }); // Put token here +builder.Services.AddSingleton(new DiscordConfiguration { Token = "MTE0MjkyMzgyNzU5MzA5NzI0Nw.GEVyUW.0MyX23SfZM9HrRiSWYJOkh-71CDFsgXfS1ul7Q", }); // Put token here // Lavalink builder.Services.AddLavalink(); @@ -46,17 +45,9 @@ 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 { @@ -64,7 +55,7 @@ Task SetResult(DiscordClient client, ReadyEventArgs eventArgs) }; await _audioService.Players - .JoinAsync(0, 0, playerOptions, stoppingToken) // Ids + .JoinAsync(1023169934819328031, 1023169936790663208, playerOptions, stoppingToken) // Ids .ConfigureAwait(false); } } \ No newline at end of file