discordjs/discord.js · error · DiscordjsTypeError
CommandInteractionOptionInvalidChannelType
CommandInteractionOptionInvalidChannelType
Error message
CommandInteractionOptionInvalidChannelType
What it means
CommandInteractionOptionInvalidChannelType is thrown by getChannel when the resolved channel option's channel type is not included in the `channelTypes` argument you passed. It lets a command restrict a channel option to specific types (e.g. only GuildText or GuildVoice); if the user supplies a channel of a disallowed type, the resolver throws instead of returning it.
Source
Thrown at packages/discord.js/src/structures/CommandInteractionOptionResolver.js:172
const option = this._getTypedOption(name, [ApplicationCommandOptionType.Boolean], ['value'], required);
return option?.value ?? null;
}
/**
* Gets a channel option.
*
* @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found.
* @param {ChannelType[]} [channelTypes=[]] The allowed types of channels. If empty, all channel types are allowed.
* @returns {?(GuildChannel|ThreadChannel|APIChannel)}
* The value of the option, or null if not set and not required.
*/
getChannel(name, required = false, channelTypes = []) {
const option = this._getTypedOption(name, [ApplicationCommandOptionType.Channel], ['channel'], required);
const channel = option?.channel ?? null;
if (channel && channelTypes.length > 0 && !channelTypes.includes(channel.type)) {
throw new DiscordjsTypeError(
ErrorCodes.CommandInteractionOptionInvalidChannelType,
name,
channel.type,
channelTypes.join(', '),
);
}
return channel;
}
/**
* Gets a string option.
*
* @param {string} name The name of the option.
* @param {boolean} [required=false] Whether to throw an error if the option is not found.
* @returns {?string} The value of the option, or null if not set and not required.
*/
getString(name, required = false) {View on GitHub (pinned to a81ed8a306)
Solutions
- Restrict the option in the builder with addChannelOption(...).addChannelTypes(ChannelType.GuildText, ...) so the Discord client only offers valid channels
- Update the channelTypes array in getChannel to include the types you actually intend to accept
- Use the current ChannelType enum values from discord.js rather than raw numbers, since enum values changed across major versions
- Reply with a friendly validation message instead of letting the resolver throw: call getChannel without channelTypes and validate channel.type yourself
Example fix
// before
.addChannelOption(o => o.setName('channel').setDescription('target'))
// after
.addChannelOption(o => o.setName('channel').setDescription('target').addChannelTypes(ChannelType.GuildText)) Defensive patterns
Strategy: validation
Validate before calling
const ch = interaction.options.getChannel('channel');
if (ch && !allowedTypes.includes(ch.type)) {
return interaction.reply({ content: 'Please pick a text channel.', ephemeral: true });
} Type guard
function isChannelOfType(channel, types) {
return channel != null && types.includes(channel.type);
} Try / catch
try {
const ch = interaction.options.getChannel('channel', true, [ChannelType.GuildText]);
} catch (err) {
if (err.code === 'CommandInteractionOptionInvalidChannelType') {
return interaction.reply({ content: 'Unsupported channel type.', ephemeral: true });
}
throw err;
} Prevention
- Restrict channel types at the builder level with addChannelTypes()
- Import ChannelType from discord.js instead of hardcoding numeric values
- Validate channel.type manually for friendly user feedback
- Re-check accepted types after discord.js major upgrades
When it happens
Trigger: Calling interaction.options.getChannel('name', required, [ChannelType.GuildText]) and the user selected a channel whose type is not in the array — e.g. a voice or category channel passed where only text channels are accepted.
Common situations: User picks any channel from the picker because the option's builder-level channel_types were not restricted, relying only on runtime check; passing channel type enum values that don't match the current discord.js ChannelType enum (version changes renamed enum members); accepting channels from DMs/threads unintentionally.
Related errors
- CommandInteractionOptionNotFound
- CommandInteractionOptionType
- CommandInteractionOptionEmpty
- CommandInteractionOptionNoSubcommand
- CommandInteractionOptionNoSubcommandGroup
AI-assisted analysis of discordjs/discord.js@a81ed8a306 (2026-08-30).
Data as JSON: /api/errors/7431ed0f5dd482ac.
Report an issue: GitHub.