Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
433 changes: 433 additions & 0 deletions Clawleash.Abstractions/README-en.md

Large diffs are not rendered by default.

433 changes: 433 additions & 0 deletions Clawleash.Abstractions/README.md

Large diffs are not rendered by default.

162 changes: 162 additions & 0 deletions Clawleash.Interfaces.Discord/README-en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Clawleash.Interfaces.Discord

A complete implementation of Discord Bot chat interface. Uses Discord.NET to receive messages from Discord servers and DMs, integrating with the AI agent.

## Features

- **Real-time Message Reception**: Real-time message monitoring using Gateway Intents
- **Command Prefix Support**: Identify commands with prefixes like `!`
- **Thread Replies**: Respond in reply format to original messages
- **DM Support**: Works in direct messages (no prefix required)
- **Streaming Send**: Support for batch sending of long messages

## Architecture

```mermaid
flowchart TB
subgraph Interface["DiscordChatInterface (C#)"]
subgraph Client["DiscordSocketClient (Discord.NET)"]
Intent["Gateway Intents"]
Events["Message Received Events"]
end
end
Client -->|WebSocket| Gateway["Discord Gateway<br/>(WebSocket)"]
```

## Usage

### Settings

```csharp
var settings = new DiscordSettings
{
Token = "YOUR_BOT_TOKEN",
CommandPrefix = "!",
UseThreads = false,
UseEmbeds = true
};
```

### Basic Usage

```csharp
var chatInterface = new DiscordChatInterface(settings, logger);

// Event handler
chatInterface.MessageReceived += (sender, args) =>
{
Console.WriteLine($"Message from {args.SenderName}: {args.Content}");
Console.WriteLine($"Guild: {args.Metadata["GuildName"]}");
Console.WriteLine($"Channel: {args.Metadata["ChannelName"]}");
Console.WriteLine($"Is DM: {args.Metadata["IsDirectMessage"]}");
};

// Start
await chatInterface.StartAsync(cancellationToken);

// Send message (reply format)
await chatInterface.SendMessageAsync("Hello!", replyToMessageId);

// Dispose
await chatInterface.DisposeAsync();
```

## Configuration Options

| Property | Description | Default |
|-----------|------|-----------|
| `Token` | Discord Bot Token | (Required) |
| `CommandPrefix` | Command prefix (ignored in DMs) | `!` |
| `UseThreads` | Whether to reply in threads | `false` |
| `UseEmbeds` | Whether to use embed messages | `true` |

## Events

### MessageReceived

Event raised when a message is received.

```csharp
chatInterface.MessageReceived += (sender, args) =>
{
// args.MessageId - Message ID
// args.SenderId - Sender Discord ID
// args.SenderName - Sender name (global name preferred)
// args.Content - Message content (prefix removed)
// args.ChannelId - Channel ID
// args.Timestamp - Timestamp
// args.Metadata["GuildId"] - Server ID
// args.Metadata["GuildName"] - Server name
// args.Metadata["ChannelName"] - Channel name
// args.Metadata["IsDirectMessage"] - Whether it's a DM
// args.Metadata["IsThread"] - Whether it's a thread
};
```

## Bot Setup

### Required Permissions

- **Read Messages**: Read messages
- **Send Messages**: Send messages
- **Read Message History**: Read message history (for replies)
- **View Channels**: View channels

### Gateway Intents

The following Intents are required:

- `MessageContent` - Read message content
- `GuildMessages` - Receive server messages
- `DirectMessages` - Receive DMs

## Troubleshooting

### "Privileged intent provided is not enabled"

Enable Message Content Intent in Bot settings:
1. Open Discord Developer Portal
2. Select the target application
3. Bot tab → Privileged Gateway Intents
4. Enable "Message Content Intent"

### "Discord token is not configured"

Verify Token is correctly set in `appsettings.json`:

```json
{
"ChatInterface": {
"Discord": {
"Enabled": true,
"Token": "${DISCORD_BOT_TOKEN}"
}
}
}
```

### Commands Not Responding

- Verify command prefix is correct
- Check if bot has access to the channel
- In DMs, send without prefix

## Build

```bash
cd Clawleash.Interfaces.Discord
dotnet build
```

## Dependencies

- Discord.NET (latest stable)
- Clawleash.Abstractions

## Related Projects

- [Clawleash.Abstractions](../Clawleash.Abstractions/README-en.md) - Shared interfaces

## License

MIT
162 changes: 162 additions & 0 deletions Clawleash.Interfaces.Discord/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Clawleash.Interfaces.Discord

Discord Bot チャットインターフェースの完全実装。Discord.NET を使用して Discord サーバーおよび DM からメッセージを受信し、AI エージェントと連携します。

## 機能

- **リアルタイムメッセージ受信**: Gateway Intents を使用したリアルタイムメッセージ監視
- **コマンドプレフィックス対応**: `!` などのプレフィックスでコマンドを識別
- **スレッド返信**: 元のメッセージに対する返信形式で応答
- **DM 対応**: ダイレクトメッセージでも動作(プレフィックス不要)
- **ストリーミング送信**: 長いメッセージの一括送信対応

## アーキテクチャ

```mermaid
flowchart TB
subgraph Interface["DiscordChatInterface (C#)"]
subgraph Client["DiscordSocketClient (Discord.NET)"]
Intent["Gateway Intents"]
Events["Message Received Events"]
end
end
Client -->|WebSocket| Gateway["Discord Gateway<br/>(WebSocket)"]
```

## 使用方法

### 設定

```csharp
var settings = new DiscordSettings
{
Token = "YOUR_BOT_TOKEN",
CommandPrefix = "!",
UseThreads = false,
UseEmbeds = true
};
```

### 基本的な使用

```csharp
var chatInterface = new DiscordChatInterface(settings, logger);

// イベントハンドラー
chatInterface.MessageReceived += (sender, args) =>
{
Console.WriteLine($"Message from {args.SenderName}: {args.Content}");
Console.WriteLine($"Guild: {args.Metadata["GuildName"]}");
Console.WriteLine($"Channel: {args.Metadata["ChannelName"]}");
Console.WriteLine($"Is DM: {args.Metadata["IsDirectMessage"]}");
};

// 開始
await chatInterface.StartAsync(cancellationToken);

// メッセージ送信(返信形式)
await chatInterface.SendMessageAsync("Hello!", replyToMessageId);

// 終了
await chatInterface.DisposeAsync();
```

## 設定オプション

| プロパティ | 説明 | デフォルト |
|-----------|------|-----------|
| `Token` | Discord Bot Token | (必須) |
| `CommandPrefix` | コマンドプレフィックス(DM では無視) | `!` |
| `UseThreads` | 返信をスレッドで行うかどうか | `false` |
| `UseEmbeds` | Embed メッセージを使用するかどうか | `true` |

## イベント

### MessageReceived

メッセージ受信時に発生するイベント。

```csharp
chatInterface.MessageReceived += (sender, args) =>
{
// args.MessageId - メッセージ ID
// args.SenderId - 送信者 Discord ID
// args.SenderName - 送信者名(グローバル名優先)
// args.Content - メッセージ内容(プレフィックス削除済み)
// args.ChannelId - チャンネル ID
// args.Timestamp - タイムスタンプ
// args.Metadata["GuildId"] - サーバー ID
// args.Metadata["GuildName"] - サーバー名
// args.Metadata["ChannelName"] - チャンネル名
// args.Metadata["IsDirectMessage"] - DM かどうか
// args.Metadata["IsThread"] - スレッドかどうか
};
```

## Bot 設定

### 必要な権限

- **Read Messages**: メッセージの読み取り
- **Send Messages**: メッセージの送信
- **Read Message History**: メッセージ履歴の読み取り(返信用)
- **View Channels**: チャンネルの表示

### Gateway Intents

以下の Intents が必要です:

- `MessageContent` - メッセージ内容の読み取り
- `GuildMessages` - サーバーメッセージの受信
- `DirectMessages` - DM の受信

## トラブルシューティング

### "Privileged intent provided is not enabled"

Bot 設定で Message Content Intent を有効にしてください:
1. Discord Developer Portal を開く
2. 対象のアプリケーションを選択
3. Bot タブ → Privileged Gateway Intents
4. "Message Content Intent" を有効化

### "Discord token is not configured"

`appsettings.json` で Token が正しく設定されているか確認してください:

```json
{
"ChatInterface": {
"Discord": {
"Enabled": true,
"Token": "${DISCORD_BOT_TOKEN}"
}
}
}
```

### コマンドが反応しない

- コマンドプレフィックスが正しいか確認
- Bot がチャンネルにアクセス権を持っているか確認
- DM ではプレフィックスなしで送信

## ビルド

```bash
cd Clawleash.Interfaces.Discord
dotnet build
```

## 依存関係

- Discord.NET (最新安定版)
- Clawleash.Abstractions

## 関連プロジェクト

- [Clawleash.Abstractions](../Clawleash.Abstractions/README.md) - 共有インターフェース

## ライセンス

MIT
Loading
Loading