You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

discord_slash中是否存在仅适用于语音频道的专属选项类型?

解答

在discord_slash库中可以实现仅选择语音频道的选项效果,无需使用独立的专属选项类型,只需要在定义频道类型的斜杠命令选项时,额外指定channel_types过滤参数即可。

配置完成后,用户唤起命令的选项弹窗时,下拉列表就只会展示服务器内的所有语音频道,和你截图展示的效果完全一致。
示例代码参考如下:

from discord_slash import SlashCommand
from discord_slash.model import SlashCommandOptionType
from discord import ChannelType

# 此处为已初始化的bot实例
slash = SlashCommand(bot, sync_commands=True)

@slash.slash(
    name="pick_voice_channel",
    description="测试选择语音频道",
    options=[
        {
            "name": "target_channel",
            "description": "选择一个语音频道",
            "type": SlashCommandOptionType.CHANNEL,
            "required": True,
            # 仅过滤展示语音频道
            "channel_types": [ChannelType.voice.value]
        }
    ]
)
async def pick_voice_channel(ctx, target_channel):
    await ctx.send(f"已选中语音频道:{target_channel.name}")

内容的提问来源于stack exchange,提问作者Omkaar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 00:45:03