158 lines
3.4 KiB
Markdown
158 lines
3.4 KiB
Markdown
# 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](https://dotnet.microsoft.com/download))
|
|
- A Discord Bot Token (create one at [Discord Developer Portal](https://discord.com/developers/applications))
|
|
|
|
## Quick Start
|
|
|
|
### 1. Clone and Setup
|
|
|
|
```bash
|
|
dotnet restore
|
|
```
|
|
|
|
### 2. Configure Your Bot Token
|
|
|
|
Edit `appsettings.json` and replace `YOUR_BOT_TOKEN_HERE` with your actual Discord bot token:
|
|
|
|
```json
|
|
{
|
|
"Discord": {
|
|
"BotToken": "YOUR_ACTUAL_TOKEN_HERE"
|
|
}
|
|
}
|
|
```
|
|
|
|
### 3. Run the Bot
|
|
|
|
```bash
|
|
dotnet run
|
|
```
|
|
|
|
The bot will connect to Discord and register its slash commands globally.
|
|
|
|
## Run With Docker Compose
|
|
|
|
1. Copy the example env file:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
2. Edit `.env` and set your Discord token:
|
|
|
|
```dotenv
|
|
DISCORD_BOT_TOKEN=YOUR_ACTUAL_TOKEN_HERE
|
|
```
|
|
|
|
3. Build and run with Docker Compose:
|
|
|
|
```bash
|
|
docker compose up --build -d
|
|
```
|
|
|
|
4. View logs:
|
|
|
|
```bash
|
|
docker compose logs -f
|
|
```
|
|
|
|
5. Stop the bot:
|
|
|
|
```bash
|
|
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>`:
|
|
|
|
```csharp
|
|
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
|
|
|
|
```json
|
|
{
|
|
"Discord": {
|
|
"BotToken": "YOUR_BOT_TOKEN_HERE"
|
|
},
|
|
"Logging": {
|
|
"LogLevel": {
|
|
"Default": "Information",
|
|
"Microsoft": "Warning"
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
## Troubleshooting
|
|
|
|
- **"Bot token not found"**: Set `DISCORD_BOT_TOKEN` in `.env` (Docker) or in your shell. The app falls back to `appsettings.json` if 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
|
|
|
|
- [Discord.Net Documentation](https://discordnet.dev/)
|
|
- [Discord Developer Portal](https://discord.com/developers/applications)
|
|
- [.NET Documentation](https://docs.microsoft.com/dotnet)
|
|
|
|
## License
|
|
|
|
MIT
|