Client.WaitForReadyAsync never Completes
HellGate94 opened this issue · 2 comments
HellGate94 commented
Even when using the Sample code it never completes and continues. Current workaround is to do await Task.Delay(1000);
and everything works just fine then
code used:
var builder = Host.CreateDefaultBuilder(args)
.ConfigureDiscordHost((context, config) => {
config.SocketConfig = new DiscordSocketConfig {
LogLevel = LogSeverity.Verbose,
AlwaysDownloadUsers = true,
MessageCacheSize = 200,
GatewayIntents = GatewayIntents.None,
};
config.Token = context.Configuration["Token"]!;
})
.ConfigureServices((services) => {
services.AddHostedService<BotStatusService>();
});
var host = builder.Build();
await host.RunAsync();
public class BotStatusService : DiscordClientService {
public BotStatusService(DiscordSocketClient client, ILogger<DiscordClientService> logger) : base(client, logger) {
}
protected override async Task ExecuteAsync(CancellationToken stoppingToken) {
// Wait for the client to be ready before setting the status
await Client.WaitForReadyAsync(stoppingToken);
Logger.LogInformation("Client is ready!");
await Client.SetActivityAsync(new Game("Set my status!"));
}
}
Output:
info: Discord.Addons.Hosting.Services.DiscordHostedService[0]
Discord.NET hosted service is starting
info: Discord.WebSocket.DiscordSocketClient[0]
Discord: Discord.Net v3.13.0 (API v10)
info: Discord.WebSocket.DiscordSocketClient[0]
Gateway: Connecting
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: .........
info: Discord.WebSocket.DiscordSocketClient[0]
Gateway: Connected
Hawxy commented
This appears to be a bug with Discord.Net 3.13, downgrading to 3.12 fixes the issue. I'll report this upstream.
Edit: This is caused by discord-net/Discord.Net#2800
If you require v3.13, either set AlwaysDownloadUsers
to false
or add GatewayIntents.GuildMembers
HellGate94 commented
Thanks for looking into it! While your workarounds didn't work for me, downgrading did the trick. Appreciated!