Search Results for

    NuGet NuGet Issues MIT License Stargazers


    Logo

    Color-Chan.Discord

    A Discord library made in .NET for interactions using webhooks.
    Explore the docs »

    View Demo · Report Bug · Request Feature

    Table of Contents

    1. About The Project
      • Built With
    2. Getting Started
      • Prerequisites
      • Installation
    3. Usage
    4. Roadmap
    5. Contributing
    6. License
    7. Versioning
    8. Acknowledgements

    About The Project

    Color-Chan.Discord is a powerful Discord library made to communicate with the Discord API.

    Features

    • Application commands
    • Message components
    • HTTP Webhooks
    • Modular
    • Completely asynchronous

    Built With

    • .NET 7
    • ASP.NET

    Getting Started

    To get a local copy up and running follow these simple steps.

    Prerequisites

    • .NET 7
    • ASP.NET

    Installation

    Nuget

    Color-Chan.Discord is available on NuGet.

    • Color-Chan.Discord

      Install-Package Color-Chan.Discord
      

      OR

      dotnet add package Color-Chan.Discord
      

    The induvidial components are also available on NuGet:

    • Color-Chan.Discord.Rest
    • Color-Chan.Discord.Commands
    • Color-Chan.Discord.Core
    • Color-Chan.Discord.Caching

    Cloning

    1. Clone the repo
      git clone https://github.com/Color-Chan/Color-Chan.Discord.git
      
    2. Move to the correct folder
      cd Color-Chan.Discord
      
    3. Build the repo
      dotnet build
      

    Usage

    Create a new ASP.NET project and add the following to Program.cs and Startup.cs.

    Program.cs

    You will have to replace Assembly.GetExecutingAssembly() with the assembly where your commands will be located.

    public static async Task Main(string[] args)
    {
        var host = CreateHostBuilder(args).Build();
        
        // Register all the commands in an Assembly.
        await host.RegisterSlashCommandsAsync(Assembly.GetExecutingAssembly(), config).ConfigureAwait(false); // <-----
    
        // Run the WebHost, and start accepting requests.
        await host.RunAsync().ConfigureAwait(false);
    }
    

    Startup.cs

    You will need to add your bot token, public key and application id, these can be found at discordapp.com.

    public void ConfigureServices(IServiceCollection services)
    {
        // Configure Color-Chan.Discord
        var config = new ColorChanConfigurations
        {
            SlashCommandConfigs = slashOptions =>
            {
                slashOptions.EnableAutoSync = true; // <---
            }
        };
    
        //  Replace the arguments with the data of your bot.
        //  Note: It is not recommended to hardcode them in, loading them from an environment variable or from a json file is better.
        services.AddColorChanDiscord("TOKEN", "PUBLIC_KEY", 999999999999999, config); // <---
    
        services.AddControllers();
    }
    
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        // This is needed to validate incoming interaction requests.
        app.UseColorChanDiscord(); // <---
    
        app.UseRouting();
        app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
    }
    

    Commands

    After this you can start to create your own commands! Here is a simple example on how you can do that.

    public class PongCommands : SlashCommandModule
    {
        /// <summary>
        ///     A simple Ping Pong command.
        /// </summary>
        [SlashCommand("ping", "Ping Pong!")]
        public Task<Result<IDiscordInteractionResponse>> PongAsync()
        {
            //  Return the response to Discord.
            return FromSuccess("Pong!");
        }
    }
    

    For more examples, please refer to the Samples folder

    URL

    The interaction end point is located at https://YOUR_DOMAIN.COM/api/v1/discord/interaction.
    You will need to add this URL to you application.  
    interactionUrlSetup

    Roadmap

    See the milestones for a list of proposed features.

    Contributing

    Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.

    1. Fork the Project
    2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
    3. Commit your Changes (git commit -m 'Add some AmazingFeature')
    4. Push to the Branch (git push origin feature/AmazingFeature)
    5. Open a Pull Request

    License

    Distributed under the MIT License. See LICENSE for more information.

    Versioning

    Color-Chan.Discord uses Semantic Versioning 2.0.0 for its versioning.

    Summary

    The versioning will be using the following format: MAJOR.MINOR.PATCH.

    • MAJOR version when you make incompatible API changes,
    • MINOR version when you add functionality in a backwards compatible manner, and
    • PATCH version when you make backwards compatible bug fixes.
    • Additional labels for pre-release and build metadata are available as extensions to the MAJOR.MINOR.PATCH format.

    Acknowledgements

    • Sodium.core
    • Microsoft.Extensions.Http.Polly
    • Readme-template
    • Scrutor
    • Fluent Assertions
    • Moq
    • Improve this Doc
    In This Article
    Back to top Generated by DocFX