Skip to content

Commit

Permalink
fix: connection must be made after register
Browse files Browse the repository at this point in the history
Signed-off-by: Lala Sabathil <aiko@aitsys.dev>
  • Loading branch information
Lulalaby committed Feb 7, 2024
1 parent 33dbf78 commit 520c058
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions Lavalink/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ private static async Task Main(string[] args)

var lavalink = discordClient.UseLavalink();

Console.WriteLine("Connecting to Discord...");
await discordClient.ConnectAsync();

// Use the default logger provided for easy reading
discordClient.Logger.LogInformation("Connection success! Logged in as {CurrentUserUsername}#{CurrentUserDiscriminator} ({CurrentUserId})", discordClient.CurrentUser.Username, discordClient.CurrentUser.Discriminator, discordClient.CurrentUser.Id);

// Lavalink
discordClient.Logger.LogInformation($"Connecting to lavalink...");
await lavalink.ConnectAsync(lavalinkConfig); // Make sure this is after discordClient.ConnectAsync()
discordClient.Logger.LogInformation($"Successful connection with lavalink!");

// In order not to list all the commands when adding, you can create a list of all commands with this.
var appCommandModule = typeof(ApplicationCommandsModule);
var commands = Assembly.GetExecutingAssembly().GetTypes().Where(t => appCommandModule.IsAssignableFrom(t) && !t.IsNested).ToList();
Expand All @@ -88,7 +77,17 @@ await lavalink.ConnectAsync(lavalinkConfig); // Make sure this is after discordC
foreach (var command in commands)
appCommandExt.RegisterGlobalCommands(command);

discordClient.Logger.LogInformation("Application commands registered successfully");
// Connect AFTER registering application commands
Console.WriteLine("Connecting to Discord...");
await discordClient.ConnectAsync();

// Use the default logger provided for easy reading
discordClient.Logger.LogInformation("Connection success! Logged in as {CurrentUserUsername}#{CurrentUserDiscriminator} ({CurrentUserId})", discordClient.CurrentUser.Username, discordClient.CurrentUser.Discriminator, discordClient.CurrentUser.Id);

// Lavalink
discordClient.Logger.LogInformation($"Connecting to lavalink...");
await lavalink.ConnectAsync(lavalinkConfig); // Make sure this is after discordClient.ConnectAsync()
discordClient.Logger.LogInformation($"Successful connection with lavalink!");

// Listen for commands by putting this method to sleep and relying off of DiscordClient's event listeners
await Task.Delay(-1);
Expand Down

0 comments on commit 520c058

Please sign in to comment.