agentscope.app.channelDiscordChannel
class DiscordChannel(ChannelBase)
agentscope/app/channel/_discord/_channel.py:43–571Discord 渠道,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.channel 包,继承自 ChannelBase。核心成员包括 aclose、start_listening、send_response、list_bot_chats、chat_kind、chat_name。
Discord platform channel. Declared in agentscope.app.channel. Extends ChannelBase.
嵌套类摘要Nested Class Summary
| 类Class | 类型Kind | 说明Description |
|---|---|---|
Credentials | 类class | 凭证,把智能体接入外部消息渠道与企业平台。 Discord bot credentials. |
Config | 类class | 配置,保存相关配置项。 Discord platform options. |
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
def __init__(channel_id: str, credentials: 'DiscordChannel.Credentials', config: 'DiscordChannel.Config') -> None | 初始化 `DiscordChannel` 实例。 Read the bot token and options from the validated models. |
属性摘要Property Summary
| 属性Property | 说明Description |
|---|---|
channel_id | 获取渠道标识。 The unique channel instance identifier. |
属性摘要Attribute Summary
| 属性Attribute | 类型Type | 说明Description | 值Value |
|---|---|---|---|
channel_type | — | 渠道类型字段。 | 'discord' |
display_name | — | 展示名称字段。 | 'Discord' |
description | — | `description` 字段。 | 'Bot for Discord servers, channels and DMs.' |
icon_url | — | `icon_url` 字段。 | 'https://www.google.com/s2/favicons?domain=discord.com&sz=128' |
platform_bot_id_field | — | `platform_bot_id_field` 字段。 | 'application_id' |
capabilities | — | 能力字段。 | ChannelCapability(text=True, markdown=True, image=True, file=True, interactive=True, max_message_length=_MAX_LEN) |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
async def aclose() -> Noneasync | 返回 `aclose` 结果。 Close the client this instance logged in lazily. |
async def start_listening(emit: Callable[[ChannelEvent | ChannelConfirmationResultEvent], Awaitable[None]]) -> Noneasync | 启动 `start_listening`。 Build the client, register the message handler, run the gateway (discord.py self-reconnects), and close it on exit. |
async def send_response(event: ChannelEvent, events: AsyncIterator[dict]) -> Noneasync | 发送响应。 Accumulate the reply (non-streaming) and post it as text + file attachments; present an approval card if the run parks. |
async def list_bot_chats() -> list[dict]async | 列出 `list_bot_chats`。 List every text channel the bot can see as ``{chat_id, name}``. |
async def chat_kind(chat_id: str) -> ChatKind | Noneasync | 设置聊天种类。 Private for a DM channel, group otherwise; ``None`` if the channel id can't be resolved. |
async def chat_name(chat_id: str) -> strasync | 设置聊天名称。 The channel's name; ``""`` for DMs or an unresolvable id. |
构造器详情Constructor Detail
DiscordChannel
def __init__(channel_id: str, credentials: 'DiscordChannel.Credentials', config: 'DiscordChannel.Config') -> None
初始化 DiscordChannel 实例。
Read the bot token and options from the validated models.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
channel_id | str | 渠道标识(类型 `str`)。This channel instance's unique id. |
credentials | 'DiscordChannel.Credentials' | 凭证(类型 `'DiscordChannel.Credentials'`)。Validated bot credentials (token + application id). |
config | 'DiscordChannel.Config' | 配置对象(类型 `'DiscordChannel.Config'`)。Validated platform options. |
agentscope/app/channel/_discord/_channel.py:90–112属性详情Attribute Detail
channel_type
= 'discord'渠道类型字段。
The channel type field.
agentscope/app/channel/_discord/_channel.py:46display_name
= 'Discord'展示名称字段。
The display name field.
agentscope/app/channel/_discord/_channel.py:47description
= 'Bot for Discord servers, channels and DMs.'description 字段。
The description field.
agentscope/app/channel/_discord/_channel.py:48icon_url
= 'https://www.google.com/s2/favicons?domain=discord.com&sz=128'icon_url 字段。
The icon url field.
agentscope/app/channel/_discord/_channel.py:49platform_bot_id_field
= 'application_id'platform_bot_id_field 字段。
The platform bot id field field.
agentscope/app/channel/_discord/_channel.py:50capabilities
= ChannelCapability(text=True, markdown=True, image=True, file=True, interactive=True, max_message_length=_MAX_LEN)能力字段。
The capabilities field.
agentscope/app/channel/_discord/_channel.py:81属性详情Property Detail
channel_id
def channel_id() -> str
获取渠道标识。
The unique channel instance identifier.
agentscope/app/channel/_discord/_channel.py:115–117方法详情Method Detail
aclose
async def aclose() -> None
返回 aclose 结果。
The connection loop closes its own in start_listening; this covers the client-only instances, which never run it.
agentscope/app/channel/_discord/_channel.py:119–127start_listening
async def start_listening(emit: Callable[[ChannelEvent | ChannelConfirmationResultEvent], Awaitable[None]]) -> None
启动 start_listening。
Build the client, register the message handler, run the gateway (discord.py self-reconnects), and close it on exit.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
emit | Callable[[ChannelEvent | ChannelConfirmationResultEvent], Awaitable[None]] | 用于入站事件的网关回调。Gateway callback for inbound events. |
agentscope/app/channel/_discord/_channel.py:159–238send_response
async def send_response(event: ChannelEvent, events: AsyncIterator[dict]) -> None
发送响应。
Accumulate the reply (non-streaming) and post it as text + file attachments; present an approval card if the run parks.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
event | ChannelEvent | 发送目标(聊天标识)。The send target (chat id). |
events | AsyncIterator[dict] | 运行's 会话事件。The run's session events. |
agentscope/app/channel/_discord/_channel.py:306–355list_bot_chats
async def list_bot_chats() -> list[dict]
列出 list_bot_chats。
Paginates over REST rather than reading client.guilds / guild.text_channels: those are the gateway cache, which is empty on an instance that only logged in.
agentscope/app/channel/_discord/_channel.py:384–404chat_kind
async def chat_kind(chat_id: str) -> ChatKind | None
设置聊天种类。
Private for a DM channel, group otherwise; None if the channel id can't be resolved.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
chat_id | str | 聊天标识(类型 `str`)。The Discord channel id as a string. |
agentscope/app/channel/_discord/_channel.py:406–422chat_name
async def chat_name(chat_id: str) -> str
设置聊天名称。
The channel's name; "" for DMs or an unresolvable id.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
chat_id | str | 聊天标识(类型 `str`)。The Discord channel id as a string. |
agentscope/app/channel/_discord/_channel.py:424–431嵌套类详情Nested Class Detail
Credentials
class Credentials凭证,把智能体接入外部消息渠道与企业平台。位于 agentscope.app.channel 包。
Discord bot credentials. Declared in agentscope.app.channel.
Config
class Config配置,保存相关配置项。位于 agentscope.app.channel 包。
Discord platform options. Declared in agentscope.app.channel.