hello and send messages

This commit is contained in:
Vilmos Zsombor TANCZOS 2025-04-28 14:17:01 +02:00
parent 61b0fdf733
commit 4187f4269a
4 changed files with 89 additions and 0 deletions

View file

@ -1,6 +1,8 @@
using dotenv.net;
using dotenv.net.Utilities;
using DSharpPlus;
using DSharpPlus.CommandsNext;
using DSharpPlus.CommandsNext.Exceptions;
namespace KBot;
@ -19,6 +21,35 @@ class Program
}
);
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);
}