56 lines
1.8 KiB
C#
56 lines
1.8 KiB
C#
using dotenv.net;
|
|
using dotenv.net.Utilities;
|
|
using DSharpPlus;
|
|
using DSharpPlus.CommandsNext;
|
|
using DSharpPlus.CommandsNext.Exceptions;
|
|
|
|
namespace KBot;
|
|
|
|
class Program
|
|
{
|
|
static async Task Main(string[] args)
|
|
{
|
|
DotEnv.Load();
|
|
|
|
var discord = new DiscordClient(
|
|
new DiscordConfiguration()
|
|
{
|
|
Token = EnvReader.GetStringValue("DISCORD_TOKEN"),
|
|
TokenType = TokenType.Bot,
|
|
Intents = DiscordIntents.AllUnprivileged | DiscordIntents.MessageContents,
|
|
}
|
|
);
|
|
|
|
var commands = discord.UseCommandsNext(
|
|
new CommandsNextConfiguration() { StringPrefixes = new[] { "," } }
|
|
);
|
|
|
|
commands.RegisterCommands<HelloModule>();
|
|
commands.RegisterCommands<SendModule>();
|
|
|
|
commands.CommandErrored += async (s, e) =>
|
|
{
|
|
if (e.Exception is CommandNotFoundException)
|
|
{
|
|
await e.Context.RespondAsync("Unknown command!");
|
|
}
|
|
else if (e.Exception is ChecksFailedException checksFailed)
|
|
{
|
|
await e.Context.RespondAsync("You don't have permission to use this command!");
|
|
}
|
|
else if (e.Exception is ArgumentException)
|
|
{
|
|
var command = commands.FindCommand("help " + e.Command?.Name, out string? str);
|
|
var ctx = commands.CreateContext(e.Context.Message, "", command, str);
|
|
await command?.ExecuteAsync(ctx);
|
|
}
|
|
else
|
|
{
|
|
await e.Context.RespondAsync($"An error occurred: {e.Exception.GetType().Name}");
|
|
}
|
|
};
|
|
|
|
await discord.ConnectAsync(new DSharpPlus.Entities.DiscordActivity("bing chillin"));
|
|
await Task.Delay(-1);
|
|
}
|
|
}
|