This repository serves as a Discord Bot template designed to expedite the process of creating new Discord bots. The project comes with a pre-configured setup for the bot, along with a practical example showcasing the handling of voice messages and sending them to a specified webhook.
Before you start running the project, you'll need to perform the following steps:
To use this Discord Bot template, you first need to create a Discord Application in the Discord Developer Portal. Follow these steps:
- Go to Discord Developer Portal and create a new application.
- During the application creation, generate a URL for your bot with the following permissions:
- Scope: Select
applications.commands
andbot
. - Bot Permissions: Choose
Administrator
or set specific permissions based on your bot's requirements.
- Scope: Select
Before running the project, ensure that you meet the following requirements:
Make sure you have the .NET SDK installed on your system. You can download and install it from the following link: .NET 8 SDK Download
Select one of the following IDEs to work with this project:
- Visual Studio Code: Download it from Visual Studio Code
- Visual Studio Community: Get it from Visual Studio Community
- JetBrains Rider: Download Rider from JetBrains Rider
This structure guides the user through the Discord Developer Portal configuration process before moving on to installation and project requirements, providing a logical and intuitive sequence of steps.
Follow these steps to run the project:
Before running the project, you'll need to set up some secrets. You can either follow the command-line instructions below or use Visual Studio for a more convenient setup.
Run the following commands from the main directory:
-
Initialize user secrets:
dotnet user-secrets init
-
Set
discord:token
secret:dotnet user-secrets set "discord:token" "your_discord_token" --project src/DiscordBotTemplate
-
Set
integration:webhookUrl
secret:dotnet user-secrets set "integration:webhookUrl" "your_webhook_url" --project src/DiscordBotTemplate
Optionally, you can set up secrets using Visual Studio:
- Right-click on your project in Visual Studio.
- Select "Manage User Secrets."
- Paste and complete the following JSON:
{
"discord": {
"token": "your_discord_token"
},
"integration": {
"webhookUrl": "your_webhook_url"
}
}
NOTE User secrets are recommended for development environments to avoid accidentally committing sensitive information to a remote Git repository.
Production Environment
For a production environment, it's crucial not to leave plain-text secrets in the appsettings.json
file. Instead:
- Encrypt secrets or use a vault solution such as Azure Vault or HashiCorp Vault.
- Consider leveraging environment variables within your GitHub repository.
- Remember to follow security best practices to protect sensitive information in a production setting.
To restore project dependencies, execute the following command:
dotnet restore
Change to the app directory and start the application by running:
cd src/DiscordBotTemplate
dotnet run
If you find this project helpful, learned something new, or using it to kickstart your own solution, consider showing your appreciation by giving it a star! Your support means a lot. Thank you! 🚀