Table of Contents

Class DiscordChannel

Namespace
JD.AI.Channels.Discord
Assembly
JD.AI.Channels.Discord.dll

Discord channel adapter using Discord.Net. Supports DMs, guild channels, thread-based conversations, and native slash command registration via ICommandAwareChannel.

public sealed class DiscordChannel : IChannel, IAsyncDisposable, ICommandAwareChannel, IAgentOutput
Inheritance
DiscordChannel
Implements
Inherited Members

Constructors

DiscordChannel(string, bool, IEnumerable<ulong>?, bool, bool, IEnumerable<ulong>?, IEnumerable<ulong>?)

public DiscordChannel(string botToken, bool allowBots = false, IEnumerable<ulong>? allowedBotIds = null, bool enableReactions = false, bool requireMention = true, IEnumerable<ulong>? allowedMentionRoleIds = null, IEnumerable<ulong>? privilegedUserIds = null)

Parameters

botToken string
allowBots bool
allowedBotIds IEnumerable<ulong>
enableReactions bool
requireMention bool
allowedMentionRoleIds IEnumerable<ulong>
privilegedUserIds IEnumerable<ulong>

Fields

CommandPrefix

Prefix used for slash commands (e.g., "jdai-help").

public const string CommandPrefix = "jdai-"

Field Value

string

Properties

ChannelType

Unique channel type identifier (e.g., "discord", "signal", "web").

public string ChannelType { get; }

Property Value

string

DisplayName

Display name for this channel instance.

public string DisplayName { get; }

Property Value

string

IsConnected

Whether the channel is currently connected and healthy.

public bool IsConnected { get; }

Property Value

bool

Methods

BeginStreaming()

public void BeginStreaming()

BeginThinking()

public void BeginThinking()

ConfirmToolCall(string, string?)

Render a tool confirmation prompt. Returns true if the user approves. Pauses any active spinner/progress indicator to avoid interleaved output.

public bool ConfirmToolCall(string toolName, string? args)

Parameters

toolName string
args string

Returns

bool

ConnectAsync(CancellationToken)

Connects to the messaging platform.

public Task ConnectAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

DisconnectAsync(CancellationToken)

Gracefully disconnects.

public Task DisconnectAsync(CancellationToken ct = default)

Parameters

ct CancellationToken

Returns

Task

DisposeAsync()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.

public ValueTask DisposeAsync()

Returns

ValueTask

A task that represents the asynchronous dispose operation.

EndStreaming()

public void EndStreaming()

EndThinking()

public void EndThinking()

ReactAsync(string, string, string, CancellationToken)

Adds a reaction emoji to a message. Not all channels support this — default is no-op.

public Task ReactAsync(string conversationId, string messageId, string emoji, CancellationToken ct = default)

Parameters

conversationId string
messageId string
emoji string
ct CancellationToken

Returns

Task

RegisterCommandsAsync(ICommandRegistry, CancellationToken)

Registers commands from the registry as platform-native commands. Called after ConnectAsync when commands are available.

public Task RegisterCommandsAsync(ICommandRegistry registry, CancellationToken ct = default)

Parameters

registry ICommandRegistry
ct CancellationToken

Returns

Task

RenderError(string)

public void RenderError(string message)

Parameters

message string

RenderInfo(string)

public void RenderInfo(string message)

Parameters

message string

RenderToolCall(string, string?, string)

Render a tool invocation with optional arguments summary and result. Pauses any active spinner/progress indicator to avoid interleaved output.

public void RenderToolCall(string toolName, string? args, string result)

Parameters

toolName string
args string
result string

RenderWarning(string)

public void RenderWarning(string message)

Parameters

message string

SendMessageAsync(string, string, CancellationToken)

Sends a message to the specified conversation/thread.

public Task SendMessageAsync(string conversationId, string content, CancellationToken ct = default)

Parameters

conversationId string
content string
ct CancellationToken

Returns

Task

SendMessageWithAttachmentsAsync(string, string?, IReadOnlyList<OutboundAttachment>, CancellationToken)

Sends a message with file attachments. Channels that don't support attachments fall back to sending the text content only.

public Task SendMessageWithAttachmentsAsync(string conversationId, string? content, IReadOnlyList<OutboundAttachment> attachments, CancellationToken ct = default)

Parameters

conversationId string
content string
attachments IReadOnlyList<OutboundAttachment>
ct CancellationToken

Returns

Task

WriteStreamingChunk(string)

public void WriteStreamingChunk(string text)

Parameters

text string

WriteThinkingChunk(string)

public void WriteThinkingChunk(string text)

Parameters

text string

Events

MessageReceived

Raised when a new inbound message arrives.

public event Func<ChannelMessage, Task>? MessageReceived

Event Type

Func<ChannelMessage, Task>

Remarks

Uses Func<ChannelMessage, Task> instead of EventHandler to support async handlers.