Class DiscordChannel
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
botTokenstringallowBotsboolallowedBotIdsIEnumerable<ulong>enableReactionsboolrequireMentionboolallowedMentionRoleIdsIEnumerable<ulong>privilegedUserIdsIEnumerable<ulong>
Fields
CommandPrefix
Prefix used for slash commands (e.g., "jdai-help").
public const string CommandPrefix = "jdai-"
Field Value
Properties
ChannelType
Unique channel type identifier (e.g., "discord", "signal", "web").
public string ChannelType { get; }
Property Value
DisplayName
Display name for this channel instance.
public string DisplayName { get; }
Property Value
IsConnected
Whether the channel is currently connected and healthy.
public bool IsConnected { get; }
Property Value
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
Returns
ConnectAsync(CancellationToken)
Connects to the messaging platform.
public Task ConnectAsync(CancellationToken ct = default)
Parameters
Returns
DisconnectAsync(CancellationToken)
Gracefully disconnects.
public Task DisconnectAsync(CancellationToken ct = default)
Parameters
Returns
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
conversationIdstringmessageIdstringemojistringctCancellationToken
Returns
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
registryICommandRegistryctCancellationToken
Returns
RenderError(string)
public void RenderError(string message)
Parameters
messagestring
RenderInfo(string)
public void RenderInfo(string message)
Parameters
messagestring
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
RenderWarning(string)
public void RenderWarning(string message)
Parameters
messagestring
SendMessageAsync(string, string, CancellationToken)
Sends a message to the specified conversation/thread.
public Task SendMessageAsync(string conversationId, string content, CancellationToken ct = default)
Parameters
conversationIdstringcontentstringctCancellationToken
Returns
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
conversationIdstringcontentstringattachmentsIReadOnlyList<OutboundAttachment>ctCancellationToken
Returns
WriteStreamingChunk(string)
public void WriteStreamingChunk(string text)
Parameters
textstring
WriteThinkingChunk(string)
public void WriteThinkingChunk(string text)
Parameters
textstring
Events
MessageReceived
Raised when a new inbound message arrives.
public event Func<ChannelMessage, Task>? MessageReceived
Event Type
Remarks
Uses Func<ChannelMessage, Task> instead of EventHandler to support async handlers.