javascript - Expected to receive a SlashCommandChannelOption builder, got undefined instead - Stack Overflow

While creating a mand using Discord.js v13, I encountered an interesting error that I can't seem t

While creating a mand using Discord.js v13, I encountered an interesting error that I can't seem to figure out.

If I use a mand handling system and create a mand with a channel input field via the Application Commands feature Discord created not so long ago for Developer applications, I run into the following error when running the Node.js application:

F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\Assertions.js:44
        throw new TypeError(`Expected to receive a ${instanceName} builder, got ${input === null ? 'null' : 'undefined'} instead.`);
        ^

TypeError: Expected to receive a SlashCommandChannelOption builder, got undefined instead.
    at Object.assertReturnOfBuilder (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\Assertions.js:44:15)
    at MixedClass._sharedAddOptionMethod (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\mixins\CommandOptions.js:76:22)
    at MixedClass.addChannelOption (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\mixins\CommandOptions.js:40:21)
    at Object.<anonymous> (F:\Development\eco-bot\mands\faq.js:7:10)
    at Module._pile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)

Before any questions about it are raised, yes all the other mands are properly loaded and sent to Discord's Application Commands API and Discord registers them without errors.

Here's the code that produces the issue:

const { SlashCommandBuilder } = require('@discordjs/builders')

module.exports = {
    data: new SlashCommandBuilder()
        .setName("faq")
        .setDescription("Send a FAQ question and answer in selected channel")
        .addChannelOption(channel => {
            channel
                .setName("channel")
                .setDescription("Channel you want to send the FAQ embed in")
                .setRequired(true)
        }),
    async execute (interaction) {
        await interaction.reply("Pong! :ping_pong:")
    }
}

While creating a mand using Discord.js v13, I encountered an interesting error that I can't seem to figure out.

If I use a mand handling system and create a mand with a channel input field via the Application Commands feature Discord created not so long ago for Developer applications, I run into the following error when running the Node.js application:

F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\Assertions.js:44
        throw new TypeError(`Expected to receive a ${instanceName} builder, got ${input === null ? 'null' : 'undefined'} instead.`);
        ^

TypeError: Expected to receive a SlashCommandChannelOption builder, got undefined instead.
    at Object.assertReturnOfBuilder (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\Assertions.js:44:15)
    at MixedClass._sharedAddOptionMethod (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\mixins\CommandOptions.js:76:22)
    at MixedClass.addChannelOption (F:\Development\eco-bot\node_modules\@discordjs\builders\dist\interactions\slashCommands\mixins\CommandOptions.js:40:21)
    at Object.<anonymous> (F:\Development\eco-bot\mands\faq.js:7:10)
    at Module._pile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:94:18)

Before any questions about it are raised, yes all the other mands are properly loaded and sent to Discord's Application Commands API and Discord registers them without errors.

Here's the code that produces the issue:

const { SlashCommandBuilder } = require('@discordjs/builders')

module.exports = {
    data: new SlashCommandBuilder()
        .setName("faq")
        .setDescription("Send a FAQ question and answer in selected channel")
        .addChannelOption(channel => {
            channel
                .setName("channel")
                .setDescription("Channel you want to send the FAQ embed in")
                .setRequired(true)
        }),
    async execute (interaction) {
        await interaction.reply("Pong! :ping_pong:")
    }
}
Share Improve this question asked Aug 16, 2021 at 17:47 Tony M.Tony M. 231 silver badge6 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The function you pass as an argument into .addChannelOption() method is expected to return an instance of SlashCommandChannelOption, which in your case is channel. So make sure to return the channel.

const { SlashCommandBuilder } = require('@discordjs/builders')

module.exports = {
    data: new SlashCommandBuilder()
        .setName("faq")
        .setDescription("Send a FAQ question and answer in selected channel")
        .addChannelOption(channel => {
            return channel // Add return here
                .setName("channel")
                .setDescription("Channel you want to send the FAQ embed in")
                .setRequired(true)
        }),
    async execute (interaction) {
        await interaction.reply("Pong! :ping_pong:")
    }
}

I made the same mistake. In the documentation they omit the curly braces {} so they can implicitly return the body of the callback. If you use curly braces you must use return

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745150189a4613832.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信