#getChannel does not exist for interaction.options

1 messages · Page 1 of 1 (latest)

stuck shoal
#

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


 const channelOption = interaction.options.getChannel('channel', true);```

https://discord.js.org/docs/packages/discord.js/14.14.1/CommandInteractionOptionResolver:Class

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

        ...
    }
}
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.

urban saddleBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

tawdry island
#

Type it as a ChatInputCommandInteraction. Your current type is ambiguous as to wether it's chat input or context menu.

stuck shoal
#

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 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.

tawdry island
#

not sure tbh. For Sapphire we re-export it as Command.ChatInputsomething and we do document it in the sapphire guide

stuck shoal
#

Gotcha. Thank you so much. I'll mark this as solved.