-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathProgram.cs
More file actions
52 lines (45 loc) · 2.05 KB
/
Program.cs
File metadata and controls
52 lines (45 loc) · 2.05 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
using System;
using System.Threading.Tasks;
using DSharpPlus.CommandsNext;
namespace DSharpPlus.Examples.CommandsNext.Basics
{
public static class Program
{
/// <summary>
/// The prefixes used to trigger Discord text commands through CommandsNext.
/// </summary>
private static readonly string[] _prefixes = new[] { "!" };
public static async Task Main()
{
// Check for token
// TODO: Load the token up from IConfiguration
string? token = Environment.GetEnvironmentVariable("DISCORD_TOKEN");
if (string.IsNullOrWhiteSpace(token))
{
Console.WriteLine("Please set the environment variable DISCORD_TOKEN.");
return;
}
// Create the client
DiscordClient discord = new(new DiscordConfiguration
{
Token = token,
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents
});
CommandsNextExtension commandsNext = discord.UseCommandsNext(new CommandsNextConfiguration()
{
// For brevity, we're going to use the string prefixes property.
// However, if you want to do something complicated, such as per-guild prefixes,
// you can pass a prefix resolver delegate instead.
StringPrefixes = _prefixes
});
// If we pass our assembly to CommandsNext, it will automatically
// search our program for any Command classes and register them on its own.
// This is very handy so you don't need to manually update a list when you add a new command.
commandsNext.RegisterCommands(typeof(Program).Assembly);
// Connect to the Discord gateway
await discord.ConnectAsync();
// Wait infinitely so the bot stays connected; DiscordClient.ConnectAsync is not a blocking call
await Task.Delay(-1);
}
}
}