-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (49 loc) · 2.36 KB
/
Program.cs
File metadata and controls
57 lines (49 loc) · 2.36 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
using System;
using System.Reflection;
using System.Threading.Tasks;
using DSharpPlus.Commands;
using DSharpPlus.Commands.Processors.SlashCommands;
using DSharpPlus.Commands.Processors.TextCommands;
using DSharpPlus.Commands.Processors.TextCommands.Parsing;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace DSharpPlus.Examples.Commands.Basics
{
public static class Program
{
public static async Task Main(string[] args)
{
ConfigurationBuilder configurationBuilder = new();
// you can also use environment vars, just uncomment this
// configurationBuilder.AddEnvironmentVariables("");
configurationBuilder.AddJsonFile("config.json", true, true);
configurationBuilder.AddCommandLine(args);
IConfiguration configuration = configurationBuilder.Build();
ServiceCollection serviceCollection = new();
serviceCollection.AddSingleton(configuration);
Assembly currentAssembly = typeof(Program).Assembly;
serviceCollection.AddSingleton(async serviceProvider =>
{
DiscordClient client = new(new DiscordConfiguration()
{
Token = configuration.GetValue<string>("example_bot:token") ??
throw new InvalidOperationException("Missing Discord token."),
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents | TextCommandProcessor.RequiredIntents
});
CommandsExtension extension = client.UseCommands(new()
{
DebugGuildId = configuration.GetValue<ulong?>("example_bot:debug_guild_id", null),
ServiceProvider = serviceProvider,
});
await extension.AddProcessorAsync(new TextCommandProcessor());
await extension.AddProcessorAsync(new SlashCommandProcessor());
extension.AddCommands(currentAssembly);
return client;
});
IServiceProvider serviceProvider = serviceCollection.BuildServiceProvider();
DiscordClient client = await serviceProvider.GetRequiredService<Task<DiscordClient>>();
await client.ConnectAsync();
await Task.Delay(-1);
}
}
}