-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
62 lines (50 loc) · 1.96 KB
/
Copy pathProgram.cs
File metadata and controls
62 lines (50 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using Discord;
using Discord.Interactions;
using Discord.WebSocket;
using dotenv.net;
using Gramble.Services;
using Gramble.Utility;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Gramble;
public class Program
{
private static IConfiguration _configuration;
private static IServiceProvider _services;
private static readonly DiscordSocketConfig _socketConfig = new()
{
GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers,
AlwaysDownloadUsers = true,
};
public static async Task Main(string[] args)
{
DotEnv.Load();
DotEnvUtility.Setup();
DotEnvUtility.DotEnvDictionary.TryGetValue("token", out string? token);
_configuration = new ConfigurationBuilder()
.AddYamlFile("appsettings.yml", optional: true)
.Build();
_services = new ServiceCollection()
.AddSingleton(_configuration)
.AddSingleton(_socketConfig)
.AddSingleton<DiscordSocketClient>()
.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<InteractionHandlingService>()
.BuildServiceProvider();
var client = _services.GetRequiredService<DiscordSocketClient>();
client.Log += LogAsync;
// Here we can initialize the service that will register and execute our commands
await _services.GetRequiredService<InteractionHandlingService>()
.InitializeAsync();
// Bot token can be provided from the Configuration object we set up earlier
await client.LoginAsync(TokenType.Bot, token);
await client.StartAsync();
// Never quit the program until manually forced to.
await Task.Delay(Timeout.Infinite);
}
private static Task LogAsync(LogMessage message)
{
Console.WriteLine(message.ToString());
return Task.CompletedTask;
}
}