Flash
Flash
SIASapphire - Imagine a framework
Created by Flash on 4/22/2024 in #discordjs-support
getChannel does not exist for interaction.options
Howdy, I'm trying to get a text channel from a command channel option, but I'm getting the error that 'getChannel' property doesn't exist even though it appears as a method in the docs and I've seen it in other people's code. I'm using the typescript complete example bot as a base. Npm ls returns discord.js 14.14.1
ts:32:51 - error TS2339: Property 'getChannel' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getAttachment" | ... 6 more ... | "getSubcommand">'.

const channelOption = interaction.options.getChannel('channel', true);
ts:32:51 - error TS2339: Property 'getChannel' does not exist on type 'Omit<CommandInteractionOptionResolver<CacheType>, "getMessage" | "getFocused" | "getMentionable" | "getRole" | "getAttachment" | ... 6 more ... | "getSubcommand">'.

const channelOption = interaction.options.getChannel('channel', true);
https://discord.js.org/docs/packages/discord.js/14.14.1/CommandInteractionOptionResolver:Class
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
import { ChannelType, CommandInteraction, PermissionsBitField } from 'discord.js';

@ApplyOptions<Command.Options>({
name: 'set-image-channel',
description: 'Sets a channel where only images are allowed',
requiredUserPermissions: [PermissionsBitField.Flags.ManageGuild],
preconditions: ['GuildOnly']
})
export class UserCommand extends Command {

private configPath = path.join(process.cwd(), 'config.json');
public override registerApplicationCommands(registry: Command.Registry): void {
registry.registerChatInputCommand((builder) =>
builder
.setName('set-image-channel')
.setDescription(this.description)
.addChannelOption(option =>
option.setName('channel')
.setDescription('')
.setRequired(true)
.addChannelTypes(ChannelType.GuildText)
)
);
}

public override async chatInputRun(interaction: CommandInteraction) {
const channelOption = interaction.options.getChannel('channel', true);

...
}
}
import { ApplyOptions } from '@sapphire/decorators';
import { Command } from '@sapphire/framework';
import { ChannelType, CommandInteraction, PermissionsBitField } from 'discord.js';

@ApplyOptions<Command.Options>({
name: 'set-image-channel',
description: 'Sets a channel where only images are allowed',
requiredUserPermissions: [PermissionsBitField.Flags.ManageGuild],
preconditions: ['GuildOnly']
})
export class UserCommand extends Command {

private configPath = path.join(process.cwd(), 'config.json');
public override registerApplicationCommands(registry: Command.Registry): void {
registry.registerChatInputCommand((builder) =>
builder
.setName('set-image-channel')
.setDescription(this.description)
.addChannelOption(option =>
option.setName('channel')
.setDescription('')
.setRequired(true)
.addChannelTypes(ChannelType.GuildText)
)
);
}

public override async chatInputRun(interaction: CommandInteraction) {
const channelOption = interaction.options.getChannel('channel', true);

...
}
}
7 replies