-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBot.cs
More file actions
64 lines (50 loc) · 2 KB
/
Bot.cs
File metadata and controls
64 lines (50 loc) · 2 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
63
64
using System.Reflection;
using DisCatSharp;
using DisCatSharp.CommandsNext;
using DisCatSharp.Enums;
using Newtonsoft.Json;
namespace SkinGenBot;
public class Bot
{
private static string _botToken = string.Empty;
public static async Task MainAsync()
{
var discord = new DiscordClient(new DiscordConfiguration()
{
Token = _botToken,
TokenType = TokenType.Bot,
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContent
});
var commands = discord.UseCommandsNext(new CommandsNextConfiguration()
{
StringPrefixes = new List<string> { "?" }
});
RegisterAllCommands(commands);
await discord.ConnectAsync();
await Task.Delay(-1);
}
// There's probably a better way to do this
public static void InitJson()
{
string filePath = Path.Combine(Environment.CurrentDirectory, "BotToken.json");
if (!File.Exists(filePath))
{
string token = ConsoleApp.Input("BotToken.json file not found. Creating a new one...\nEnter your bot's token below:\n");
var botConfig = new { Token = token };
string jsonContent = JsonConvert.SerializeObject(botConfig, Formatting.Indented);
File.WriteAllText(filePath, jsonContent);
Console.WriteLine("BotToken.json was created with your token.");
}
string fileContent = File.ReadAllText(filePath);
dynamic botConfigObj = JsonConvert.DeserializeObject(fileContent);
_botToken = botConfigObj.Token;
}
private static void RegisterAllCommands(CommandsNextExtension commands)
{
var commandClasses = Assembly.GetExecutingAssembly().GetTypes().Where(type => type.IsClass && !type.IsAbstract && type.IsSubclassOf(typeof(BaseCommandModule))).ToList();
foreach (var commandClass in commandClasses)
{
commands.RegisterCommands(commandClass);
}
}
}