Search code examples
node.jsdiscord.js

Discord.js creating channel error - Invalid Form Body


I've been trying to create a ticket bot and create channels that have tickets within them. However, when I try and create them it returns an error

Code:

const channel = await interaction.guild.channels.create(`ticket-${interaction.user.username}`, {
     parent: '929135588949512232',
     topic: interaction.user.id,
     type: 'GUILD_TEXT',
})

Error:

DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required

error

Any help would be appreaciated


Solution

  • If you look at the documentation, only one parameter is required for the channel create method, therefore the code should look like this:

    const channel = await interaction.guild.channels.create({
            name: `ticket-${message.interaction.username}`,
            parent: "929135588949512232",
            topic: interaction.user.id,
            type: Discord.ChannelType.GuildText,
        });
    

    Refer to the docs here https://discord.js.org/#/docs/discord.js/main/class/GuildChannelManager?scrollTo=create

    The error is caused, because you passed in information, such as the type, in the second parameter, not the first.