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

使用WOKCommands时如何配置斜杠命令仅允许选择语音频道

实现斜杠命令仅可选语音频道的解决方案

你只需要在原有的CHANNEL类型选项配置中新增channelTypes字段,指定仅允许语音频道类型即可,修改后的代码如下:

options: [
        {
            name: 'channel',
            description: '🔊 Voice channel in which you want to play your activity',
            required: true,
            type: discord_js_1.default.Constants.ApplicationCommandOptionTypes.CHANNEL,
            // 新增以下配置,仅允许选择服务器语音频道
            channelTypes: [discord_js_1.default.Constants.ChannelType.GUILD_VOICE]
        },
    ],

如果你使用的是discord.js v14版本,对应写法调整为:

const { ChannelType, ApplicationCommandOptionType } = require('discord.js');

// 选项部分配置
options: [
        {
            name: 'channel',
            description: '🔊 你想要启动活动的语音频道',
            required: true,
            type: ApplicationCommandOptionType.Channel,
            channelTypes: [ChannelType.GuildVoice]
        },
    ]
  • 如果你需要同时允许其他频道类型,只需要在channelTypes数组中追加对应的频道类型枚举值即可,比如需要同时允许舞台频道的话加上GUILD_STAGE_VOICE(v14对应ChannelType.GuildStageVoice)即可
  • 配置完成后重新注册一次斜杠命令,配置就会生效,用户在选择频道时只会看到符合类型的语音频道,其他文本、分类、公告频道都会被自动过滤掉

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.02 23:42:02