AS AgentScopeAPI 手册 / API Reference
类class agentscope.app.channel

DiscordChannel

class DiscordChannel(ChannelBase)
源码Source agentscope/app/channel/_discord/_channel.py:43–571

Discord 渠道,把智能体接入外部消息渠道与企业平台。位于 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.

参数Parameters
名称Name类型Type说明Description
channel_idstr渠道标识(类型 `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.
源码Source agentscope/app/channel/_discord/_channel.py:90–112

属性详情Attribute Detail

channel_type

 = 'discord'

渠道类型字段。

The channel type field.

源码Source agentscope/app/channel/_discord/_channel.py:46

display_name

 = 'Discord'

展示名称字段。

The display name field.

源码Source agentscope/app/channel/_discord/_channel.py:47

description

 = 'Bot for Discord servers, channels and DMs.'

description 字段。

The description field.

源码Source agentscope/app/channel/_discord/_channel.py:48

icon_url

 = 'https://www.google.com/s2/favicons?domain=discord.com&sz=128'

icon_url 字段。

The icon url field.

源码Source agentscope/app/channel/_discord/_channel.py:49

platform_bot_id_field

 = 'application_id'

platform_bot_id_field 字段。

The platform bot id field field.

源码Source agentscope/app/channel/_discord/_channel.py:50

capabilities

 = ChannelCapability(text=True, markdown=True, image=True, file=True, interactive=True, max_message_length=_MAX_LEN)

能力字段。

The capabilities field.

源码Source agentscope/app/channel/_discord/_channel.py:81

属性详情Property Detail

channel_id

def channel_id() -> str

获取渠道标识。

The unique channel instance identifier.

返回Returns str
返回字符串结果。Returns a string.
源码Source agentscope/app/channel/_discord/_channel.py:115–117

方法详情Method Detail

aclose

async def aclose() -> None
async

返回 aclose 结果。

The connection loop closes its own in start_listening; this covers the client-only instances, which never run it.

返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_discord/_channel.py:119–127

start_listening

async def start_listening(emit: Callable[[ChannelEvent | ChannelConfirmationResultEvent], Awaitable[None]]) -> None
async

启动 start_listening。

Build the client, register the message handler, run the gateway (discord.py self-reconnects), and close it on exit.

参数Parameters
名称Name类型Type说明Description
emitCallable[[ChannelEvent | ChannelConfirmationResultEvent], Awaitable[None]]用于入站事件的网关回调。Gateway callback for inbound events.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_discord/_channel.py:159–238

send_response

async def send_response(event: ChannelEvent, events: AsyncIterator[dict]) -> None
async

发送响应。

Accumulate the reply (non-streaming) and post it as text + file attachments; present an approval card if the run parks.

参数Parameters
名称Name类型Type说明Description
eventChannelEvent发送目标(聊天标识)。The send target (chat id).
eventsAsyncIterator[dict]运行's 会话事件。The run's session events.
返回Returns None
无返回值。No value is returned.
源码Source agentscope/app/channel/_discord/_channel.py:306–355

list_bot_chats

async def list_bot_chats() -> list[dict]
async

列出 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.

返回Returns list[dict]
返回dict列表。Returns a list of dict.
源码Source agentscope/app/channel/_discord/_channel.py:384–404

chat_kind

async def chat_kind(chat_id: str) -> ChatKind | None
async

设置聊天种类。

Private for a DM channel, group otherwise; None if the channel id can't be resolved.

参数Parameters
名称Name类型Type说明Description
chat_idstr聊天标识(类型 `str`)。The Discord channel id as a string.
返回Returns ChatKind | None
返回ChatKind|None。Returns chat kind none.
源码Source agentscope/app/channel/_discord/_channel.py:406–422

chat_name

async def chat_name(chat_id: str) -> str
async

设置聊天名称。

The channel's name; "" for DMs or an unresolvable id.

参数Parameters
名称Name类型Type说明Description
chat_idstr聊天标识(类型 `str`)。The Discord channel id as a string.
返回Returns str
返回字符串结果。Returns a string.
源码Source 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.

继承成员Inherited Members

基于官方固定版本源码静态生成Generated from pinned official sources · Python 2.0.11 · Java 2.0.4
签名与文档为静态抽取;如有疑问请以源码为准。Signatures and docs are extracted statically; verify against the source when in doubt.