using shards to see if it fixes connection issues

This commit is contained in:
José Henrique Ivanchechen 2023-02-15 21:47:26 -03:00
parent 9be2ffc54a
commit 00022c1cb9
5 changed files with 15 additions and 19 deletions

@ -10,7 +10,7 @@
<ItemGroup>
<PackageReference Include="Discord.Net" Version="3.9.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
<PackageReference Include="YoutubeExplode" Version="6.2.5" />
<PackageReference Include="YoutubeExplode" Version="6.2.6" />
</ItemGroup>
</Project>

@ -5,7 +5,7 @@ using TextCommandFramework.Services;
namespace TextCommandFramework.Modules
{
public class PublicModule : ModuleBase<SocketCommandContext>
public class PublicModule : ModuleBase<ShardedCommandContext>
{
public PictureService PictureService { get; set; }
public PlayerService PlayerService { get; set; }

@ -26,15 +26,15 @@ namespace TextCommandFramework
using (var services = ConfigureServices())
{
var client = services.GetRequiredService<DiscordSocketClient>();
var client = services.GetRequiredService<DiscordShardedClient>();
client.Log += LogAsync;
client.LoggedIn += () => Client_LoggedIn(client);
client.Ready += () => Client_Ready(client);
client.ShardReady += (shard) => Client_Ready(shard);
services.GetRequiredService<CommandService>().Log += LogAsync;
await Connect(client);
//client.Disconnected += async (ex) => await Connect(client);
await client.LoginAsync(TokenType.Bot, TOKEN);
await client.StartAsync();
await services.GetRequiredService<CommandHandlingService>().InitializeAsync();
@ -42,12 +42,6 @@ namespace TextCommandFramework
}
}
public async Task Connect(DiscordSocketClient client)
{
await client.LoginAsync(TokenType.Bot, TOKEN);
await client.StartAsync();
}
private async Task Client_Ready(DiscordSocketClient client)
{
var announceLoginGuild = ulong.Parse(Environment.GetEnvironmentVariable("ANNOUNCE_LOGIN_GUILD") ?? "0");
@ -69,7 +63,7 @@ namespace TextCommandFramework
await channel.SendMessageAsync("@everyone LIVE!");
}
private Task Client_LoggedIn(DiscordSocketClient client)
private Task Client_LoggedIn(DiscordShardedClient client)
{
Console.WriteLine("Successfully logged in!");
@ -88,9 +82,10 @@ namespace TextCommandFramework
return new ServiceCollection()
.AddSingleton(new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent,
TotalShards = 3
})
.AddSingleton<DiscordSocketClient>()
.AddSingleton<DiscordShardedClient>()
.AddSingleton<CommandService>()
.AddSingleton<YoutubeService>()
.AddSingleton<PlayerService>()

@ -12,7 +12,7 @@ namespace TextCommandFramework.Services
public class CommandHandlingService
{
private readonly CommandService _commands;
private readonly DiscordSocketClient _discord;
private readonly DiscordShardedClient _discord;
private readonly IServiceProvider _services;
private readonly string CommandPrefix = "!";
@ -20,7 +20,7 @@ namespace TextCommandFramework.Services
public CommandHandlingService(IServiceProvider services)
{
_commands = services.GetRequiredService<CommandService>();
_discord = services.GetRequiredService<DiscordSocketClient>();
_discord = services.GetRequiredService<DiscordShardedClient>();
_services = services;
_commands.CommandExecuted += CommandExecutedAsync;
@ -46,7 +46,7 @@ namespace TextCommandFramework.Services
//Check if the message sent has the specified prefix
if (!message.HasStringPrefix(CommandPrefix, ref argPos)) return;
var context = new SocketCommandContext(_discord, message);
var context = new ShardedCommandContext(_discord, message);
await _commands.ExecuteAsync(context, argPos, _services);
}

@ -25,7 +25,8 @@ namespace Kasbot.Services
IAudioClient audioClient = await channel.ConnectAsync();
audioClient.Disconnected += (ex) => Stop(Context.Guild.Id);
audioClient.StreamDestroyed += (ex) => Stop(Context.Guild.Id);
conn.AudioClient = audioClient;
if (Clients.ContainsKey(Context.Guild.Id))