Skip to content

This project demonstrates how to configure an extensible Discord slash command bot in C# that uses Configuration and Dependency Injection.

License

Notifications You must be signed in to change notification settings

markekraus/DiscordSlashCommandBot

Repository files navigation

DiscordSlashCommandBot - The Discord Slash Command Bot Framework

This project demonstrates how to configure an extensible Discord Slash Command bot that uses Configuration and Dependency Injection.

Table of Contents

Structure

Configuration

The AppSettings class defines the model for all application settings. These can be set:

  • With User Secrets for development.
  • In appSettings.json,
  • Or as Environment variables prefixed with DISCORD_BOT_ (e.g. DISCORD_BOT_LogLevel),

User secrets will be overwritten by appSettings.json, and those will be over written by environment variables. You can change this precedence by changing the order in which they are add in ServicesConfiguration.cs.

Dependency Injection

Dependency Injection is handled by .\DiscordSlashCommandBot\ServicesConfiguration.cs. The AddBotServices() extension method handles all configuration and registers all services and options.

Creating New Slash Commands

  1. Create class (preferably ending with Command, e.g. EchoCommand) and implement the IBotSlashCommand interface.
  2. Create and return and un-built SlashCommandBuilder in GetSlashCommandBuilder(). The BotService will build the command and register it for you. Do not implement your own command registration!
  3. Create your command handling logic in SlashCommandHandler(SocketSlashCommand command). This will be called for you by BotService when a user uses your slash command.
  4. Register the command as a singleton in ServicesConfiguration. Example: services.AddSingleton<IBotSlashCommand, EchoCommand>();

About

This project demonstrates how to configure an extensible Discord slash command bot in C# that uses Configuration and Dependency Injection.

Topics

Resources

License

Stars

Watchers

Forks

Languages