using shards to see if it fixes connection issues
This commit is contained in:
parent
9be2ffc54a
commit
00022c1cb9
@ -10,7 +10,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Discord.Net" Version="3.9.0" />
|
<PackageReference Include="Discord.Net" Version="3.9.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.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>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -5,7 +5,7 @@ using TextCommandFramework.Services;
|
|||||||
|
|
||||||
namespace TextCommandFramework.Modules
|
namespace TextCommandFramework.Modules
|
||||||
{
|
{
|
||||||
public class PublicModule : ModuleBase<SocketCommandContext>
|
public class PublicModule : ModuleBase<ShardedCommandContext>
|
||||||
{
|
{
|
||||||
public PictureService PictureService { get; set; }
|
public PictureService PictureService { get; set; }
|
||||||
public PlayerService PlayerService { get; set; }
|
public PlayerService PlayerService { get; set; }
|
||||||
|
21
Program.cs
21
Program.cs
@ -26,15 +26,15 @@ namespace TextCommandFramework
|
|||||||
using (var services = ConfigureServices())
|
using (var services = ConfigureServices())
|
||||||
{
|
{
|
||||||
|
|
||||||
var client = services.GetRequiredService<DiscordSocketClient>();
|
var client = services.GetRequiredService<DiscordShardedClient>();
|
||||||
|
|
||||||
client.Log += LogAsync;
|
client.Log += LogAsync;
|
||||||
client.LoggedIn += () => Client_LoggedIn(client);
|
client.LoggedIn += () => Client_LoggedIn(client);
|
||||||
client.Ready += () => Client_Ready(client);
|
client.ShardReady += (shard) => Client_Ready(shard);
|
||||||
services.GetRequiredService<CommandService>().Log += LogAsync;
|
services.GetRequiredService<CommandService>().Log += LogAsync;
|
||||||
|
|
||||||
await Connect(client);
|
await client.LoginAsync(TokenType.Bot, TOKEN);
|
||||||
//client.Disconnected += async (ex) => await Connect(client);
|
await client.StartAsync();
|
||||||
|
|
||||||
await services.GetRequiredService<CommandHandlingService>().InitializeAsync();
|
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)
|
private async Task Client_Ready(DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
var announceLoginGuild = ulong.Parse(Environment.GetEnvironmentVariable("ANNOUNCE_LOGIN_GUILD") ?? "0");
|
var announceLoginGuild = ulong.Parse(Environment.GetEnvironmentVariable("ANNOUNCE_LOGIN_GUILD") ?? "0");
|
||||||
@ -69,7 +63,7 @@ namespace TextCommandFramework
|
|||||||
await channel.SendMessageAsync("@everyone LIVE!");
|
await channel.SendMessageAsync("@everyone LIVE!");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Task Client_LoggedIn(DiscordSocketClient client)
|
private Task Client_LoggedIn(DiscordShardedClient client)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Successfully logged in!");
|
Console.WriteLine("Successfully logged in!");
|
||||||
|
|
||||||
@ -88,9 +82,10 @@ namespace TextCommandFramework
|
|||||||
return new ServiceCollection()
|
return new ServiceCollection()
|
||||||
.AddSingleton(new DiscordSocketConfig
|
.AddSingleton(new DiscordSocketConfig
|
||||||
{
|
{
|
||||||
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent
|
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent,
|
||||||
|
TotalShards = 3
|
||||||
})
|
})
|
||||||
.AddSingleton<DiscordSocketClient>()
|
.AddSingleton<DiscordShardedClient>()
|
||||||
.AddSingleton<CommandService>()
|
.AddSingleton<CommandService>()
|
||||||
.AddSingleton<YoutubeService>()
|
.AddSingleton<YoutubeService>()
|
||||||
.AddSingleton<PlayerService>()
|
.AddSingleton<PlayerService>()
|
||||||
|
@ -12,7 +12,7 @@ namespace TextCommandFramework.Services
|
|||||||
public class CommandHandlingService
|
public class CommandHandlingService
|
||||||
{
|
{
|
||||||
private readonly CommandService _commands;
|
private readonly CommandService _commands;
|
||||||
private readonly DiscordSocketClient _discord;
|
private readonly DiscordShardedClient _discord;
|
||||||
private readonly IServiceProvider _services;
|
private readonly IServiceProvider _services;
|
||||||
|
|
||||||
private readonly string CommandPrefix = "!";
|
private readonly string CommandPrefix = "!";
|
||||||
@ -20,7 +20,7 @@ namespace TextCommandFramework.Services
|
|||||||
public CommandHandlingService(IServiceProvider services)
|
public CommandHandlingService(IServiceProvider services)
|
||||||
{
|
{
|
||||||
_commands = services.GetRequiredService<CommandService>();
|
_commands = services.GetRequiredService<CommandService>();
|
||||||
_discord = services.GetRequiredService<DiscordSocketClient>();
|
_discord = services.GetRequiredService<DiscordShardedClient>();
|
||||||
_services = services;
|
_services = services;
|
||||||
|
|
||||||
_commands.CommandExecuted += CommandExecutedAsync;
|
_commands.CommandExecuted += CommandExecutedAsync;
|
||||||
@ -46,7 +46,7 @@ namespace TextCommandFramework.Services
|
|||||||
//Check if the message sent has the specified prefix
|
//Check if the message sent has the specified prefix
|
||||||
if (!message.HasStringPrefix(CommandPrefix, ref argPos)) return;
|
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);
|
await _commands.ExecuteAsync(context, argPos, _services);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ namespace Kasbot.Services
|
|||||||
IAudioClient audioClient = await channel.ConnectAsync();
|
IAudioClient audioClient = await channel.ConnectAsync();
|
||||||
|
|
||||||
audioClient.Disconnected += (ex) => Stop(Context.Guild.Id);
|
audioClient.Disconnected += (ex) => Stop(Context.Guild.Id);
|
||||||
|
audioClient.StreamDestroyed += (ex) => Stop(Context.Guild.Id);
|
||||||
|
|
||||||
conn.AudioClient = audioClient;
|
conn.AudioClient = audioClient;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user