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);

...
}
}
Solution:
Type it as a ChatInputCommandInteraction. Your current type is ambiguous as to wether it's chat input or context menu.
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Solution
Favna
Favna27d ago
Type it as a ChatInputCommandInteraction. Your current type is ambiguous as to wether it's chat input or context menu.
Flash
Flash27d ago
Thanks! Makes sense now that you told me and the command is working fine. I wonder if there's anyway I could have figured that out from the docs for future reference? For example, the page the ChatlnputCommandlnteraction options doesn't have getChannel, so I'm just trying to figure out how I would read this. I guess just more exposure to the code. Sorry if dumb question but am kinda new to this https://discord.js.org/docs/packages/discord.js/14.14.1/ChatInputCommandInteraction:Class#options
discord.js
discord.js
discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.
Favna
Favna26d ago
not sure tbh. For Sapphire we re-export it as Command.ChatInputsomething and we do document it in the sapphire guide
Flash
Flash26d ago
Gotcha. Thank you so much. I'll mark this as solved.
Want results from more Discord servers?
Add your server
More Posts
Editing a message deletes itTo explain my system. I have a music bot that some events trigger certain message edits. Upon a userCaching ProblemsHey, i have some problems with caching, on discord.js they sad `All Guilds are cached if you have thRegistering Context CommandsHello I want to register a context command with this code : ```js export class ValidRoroCommand exSome questionsHello, I'm new Sapphire and I don't really know how to do the followings. Right now I have 2 issues:Sapphire command not recognizedI'm trying to install and use sapphire CLI but doesn't matter if I use NPM or Yarn 4.1.1, when I insAPI Plugin PrefixHey all, for some reason my prefix isn't applying on the data paths This is my env file: ``` # API Task was not found | plugin-scheduled-tasks👋🏿 I'm getting "`[ScheduledTaskPlugin] There was no task found for "task_name"`" error for all my MongoDB Discord.JS (Only saving to 1 profile)```js const { Client, Message } = require('discord.js'); const calculateLevelXp = require('./calculaCan't load subcommandHello, i'm trying to update to the latest djs and sapphire versions (from djs v13 and sapphire v3) amultiplie registered handlersHi, is it better to split for example the button interactions for different buttons to different filTypeScript CheckHey. The code works but I am curious if there is any way to do a better coding job like cleaniness eVariable parameter type based on the previous variableI want to add a 'parametric' `set` subcommand to one of my commands For that command the values cancreate a command that has spaces as one argfor example, i would want a command with multiple spaces for each arg, such as `!command <argwithspaHelp fetching usersI didn't know if this was a sapphire or d.js issue but this line of code im using to fetch the users