3.4 KiB
3.4 KiB
TentacleBot - Discord .NET Bot
A Discord bot project built with Discord.Net and .NET 8+, featuring dependency injection and slash commands.
Features
- ? Built with Discord.Net 3.14+
- ? Dependency Injection for services
- ? Slash commands support
- ? Rich embed messages
- ? Example commands included
- ? .NET 8 or higher
Prerequisites
- .NET 8.0 or higher (download here)
- A Discord Bot Token (create one at Discord Developer Portal)
Quick Start
1. Clone and Setup
dotnet restore
2. Configure Your Bot Token
Edit appsettings.json and replace YOUR_BOT_TOKEN_HERE with your actual Discord bot token:
{
"Discord": {
"BotToken": "YOUR_ACTUAL_TOKEN_HERE"
}
}
3. Run the Bot
dotnet run
The bot will connect to Discord and register its slash commands globally.
Run With Docker Compose
- Copy the example env file:
cp .env.example .env
- Edit
.envand set your Discord token:
DISCORD_BOT_TOKEN=YOUR_ACTUAL_TOKEN_HERE
- Build and run with Docker Compose:
docker compose up --build -d
- View logs:
docker compose logs -f
- Stop the bot:
docker compose down
Project Structure
TentacleBot/
„¥„Ÿ„Ÿ Program.cs # Entry point and DI setup
„¥„Ÿ„Ÿ Services/
„ „¤„Ÿ„Ÿ BotService.cs # Core bot service
„¥„Ÿ„Ÿ Commands/
„ „¤„Ÿ„Ÿ GeneralCommands.cs # Example slash commands
„¥„Ÿ„Ÿ appsettings.json # Configuration
„¥„Ÿ„Ÿ Dockerfile # Container image definition
„¥„Ÿ„Ÿ docker-compose.yml # Local compose setup
„¥„Ÿ„Ÿ .env.example # Environment variable template
„¥„Ÿ„Ÿ TentacleBot.csproj # Project file
„¤„Ÿ„Ÿ README.md # This file
Example Commands
The bot includes example slash commands:
/general ping- Shows bot latency/general hello [user]- Greet a user/general botinfo- Display bot information
Adding New Commands
Create a new class in the Commands folder that inherits from InteractionModuleBase<SocketInteractionContext>:
using Discord.Interactions;
namespace TentacleBot.Commands;
public class MyCommands : InteractionModuleBase<SocketInteractionContext>
{
[SlashCommand("mycommand", "My custom command")]
public async Task HandleMyCommandAsync()
{
await RespondAsync("Hello from my command!");
}
}
Commands are automatically discovered and registered when the bot starts.
Configuration
appsettings.json
{
"Discord": {
"BotToken": "YOUR_BOT_TOKEN_HERE"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning"
}
}
}
Troubleshooting
- "Bot token not found": Set
DISCORD_BOT_TOKENin.env(Docker) or in your shell. The app falls back toappsettings.jsonif the env var is not set - "Insufficient permissions": Ensure your bot has the necessary permissions in Discord Developer Portal
- Commands not appearing: The bot needs to connect first. Wait a few seconds after starting, then try
/in Discord
Resources
License
MIT