Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Program
- {
- private readonly IConfiguration _configuration;
- private readonly IServiceProvider _services;
- private readonly DiscordSocketConfig _socketConfig = new()
- {
- GatewayIntents = (GatewayIntents.AllUnprivileged | GatewayIntents.MessageContent | GatewayIntents.GuildMembers) ^ GatewayIntents.GuildBans,
- LogGatewayIntentWarnings = false,
- AlwaysDownloadUsers = true,
- };
- public Program()
- {
- _configuration = new ConfigurationBuilder()
- .AddEnvironmentVariables(prefix: "DC_")
- .AddJsonFile("config.json", optional: true)
- .Build();
- _services = new ServiceCollection()
- .AddSingleton(_configuration)
- .AddSingleton(_socketConfig)
- .AddSingleton<DiscordSocketClient>()
- .AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
- .AddSingleton<InteractionHandler>()
- .AddSingleton<IUserSettingHandler, UserSettingHandler>()
- .AddSingleton<IPostwmClass, PostwmClass>()
- .AddSingleton<IUserTranslationsHandler, UserTranslationsHandler>()
- .AddSingleton<UserSettingHandler>()
- .AddSingleton<PostwmClass>()
- .AddSingleton<UserTranslationsHandler>()
- .BuildServiceProvider();
- }
- static void Main(string[] args)
- => new Program().RunAsync()
- .GetAwaiter()
- .GetResult();
- public async Task RunAsync()
- {
- var client = _services.GetRequiredService<DiscordSocketClient>();
- client.Log += LogAsync;
- // Here we can initialize the service that will register and execute our commands
- await _services.GetRequiredService<InteractionHandler>()
- .InitializeAsync();
- // Bot token can be provided from the Configuration object we set up earlier
- await client.LoginAsync(TokenType.Bot, _configuration["botToken"]);
- await client.StartAsync();
- // Never quit the program until manually forced to.
- await Task.Delay(Timeout.Infinite);
- }
- #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
- private async Task LogAsync(LogMessage message)
- #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously
- => Console.WriteLine(message.ToString());
- public static bool IsDebug()
- {
- #if DEBUG
- return true;
- #else
- return false;
- #endif
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement