A Discord library made in .NET for interactions using webhooks.
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Color-Chan.Discord is a powerful Discord library made to communicate with the Discord API.
- Application commands
- Message components
- HTTP Webhooks
- Modular
- Completely asynchronous
To get a local copy up and running follow these simple steps.
Color-Chan.Discord is available on NuGet.
-
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
- Clone the repo
git clone https://github.com/Color-Chan/Color-Chan.Discord.git
- Move to the correct folder
cd Color-Chan.Discord
- Build the repo
dotnet build
Create a new ASP.NET project and add the following to Program.cs and Startup.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);
}
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(); });
}
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
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.
See the milestones for a list of proposed features.
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.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Color-Chan.Discord uses Semantic Versioning 2.0.0 for its versioning.
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.