NetCordDev / NetCord

The modern and fully customizable C# Discord library.
https://netcord.dev
MIT License
65 stars 10 forks source link
bot discord discord-api discord-api-framework discord-api-library discord-api-wrapper discord-bot discord-framework discord-library discord-wrapper framework library wrapper

Logo

The modern and fully customizable C# Discord library

⭐ If you like this project, please consider giving it a star! ⭐

Table of Contents

  1. πŸ“¦ Installation
  2. πŸš€ Showcase
  3. 🎨 Features
  4. πŸ₯… Goals
  5. πŸ“š Guides
  6. πŸ“„ Documentation
  7. 🩹 Support
  8. πŸ“œ License

1. πŸ“¦ Installation

You can install NetCord packages via NuGet package manager:

Package Description
NetCord Core package with fundamental functionality.
NetCord.Services Facilitates seamless handling of commands and interactions.
NetCord.Hosting Provides .NET Generic Host extensions for the NetCord package.
NetCord.Hosting.Services Provides .NET Generic Host extensions for the NetCord.Services package.
NetCord.Hosting.AspNetCore Provides ASP.NET Core extensions for seamless handling of HTTP interactions.

2. πŸš€ Showcase

This snippet showcases a bot with a minimal API-style /square command and includes a module-based /greet command.

Required usings omitted for readability, click here to show ```cs using Microsoft.Extensions.Hosting; using NetCord; using NetCord.Services.ApplicationCommands; using NetCord.Hosting.Gateway; using NetCord.Hosting.Services.ApplicationCommands; ```

Minimal API-style Bot Example

The following example sets up a bot with a minimal API-style approach for the /square command, which calculates the square of a number:

var builder = Host.CreateDefaultBuilder(args)
    .UseDiscordGateway()
    .UseApplicationCommands<SlashCommandInteraction, SlashCommandContext>();

var host = builder.Build()
    .AddSlashCommand<SlashCommandContext>("square", "Square!", (int a) => $"{a}Β² = {a * a}")
    .UseGatewayEventHandlers();

await host.RunAsync();

Module-based Command Example

Moreover, you can use a module-based approach. Here's an example of a /greet command that greets a specified user:

public class GreetingModule : ApplicationCommandModule<SlashCommandContext>
{
    [SlashCommand("greet", "Greet someone!")]
    public string Greet(User user) => $"{Context.User} greets {user}!";
}

3. 🎨 Features

4. πŸ₯… Goals

NetCord's goal is to allow .NET developers to create fully customizable Discord bots without fighting the API wrapper itself. NetCord is designed to be easy to use and fully customizable, while still being lightweight and performant.

5. πŸ“š Guides

6. πŸ“„ Documentation

7. 🩹 Support

Discord

8. πŸ“œ License

This repository is released under the MIT License.