-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
47 lines (41 loc) · 1.77 KB
/
Program.cs
File metadata and controls
47 lines (41 loc) · 1.77 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
public class Program
{
public static Task Main() => new Program().MainAsync();
public async Task MainAsync()
{
using IHost host = Host.CreateDefaultBuilder()
.ConfigureServices((_, services) =>
services
.AddSingleton(x => new DiscordSocketClient(new DiscordSocketConfig
{
GatewayIntents = GatewayIntents.AllUnprivileged,
AlwaysDownloadUsers = true
}
))
.AddSingleton(x => new InteractionService(x.GetRequiredService<DiscordSocketClient>()))
.AddSingleton<MusicPlayer.InteractionHandler>()
.AddSingleton(x => new CommandService())
)
.Build();
await RunAsync(host);
}
public async Task RunAsync(IHost host)
{
using IServiceScope serviceScope = host.Services.CreateScope();
IServiceProvider provider = serviceScope.ServiceProvider;
var _client = provider.GetRequiredService<DiscordSocketClient>();
var slashCommands = provider.GetRequiredService<InteractionService>();
await provider.GetRequiredService<MusicPlayer.InteractionHandler>().InitializeAsync();
_client.Log += async (LogMessage messages) => Console.WriteLine(messages.Message);
slashCommands.Log += async (LogMessage messages) => Console.WriteLine(messages.Message);
_client.Ready += async () =>
{
Console.WriteLine($"Login as{_client.CurrentUser.Username.ToString()}");
await slashCommands.RegisterCommandsGloballyAsync(true);
};
var token = ConfigurationManager.AppSettings.Get("TOKEN");
await _client.LoginAsync(TokenType.Bot, token);
await _client.StartAsync();
await Task.Delay(-1);
}
}