javascriptnode.jsdiscord.jsbotsticket-system

DiscordAPIError[50035]: Invalid Form Body (discord.js v14)


I'm trying to make a ticket system at discord.js v14 (the new version). The config values are correct and I have checked this by console.log them. I have an embed already with custom.id = "open-ticket" and whenever I click the first option it gets me this error:

module.exports = {
    name: 'interactionCreate',
    async execute(interaction, client) {
        const command = client.commands.get(interaction.commandName);

        if (!command && interaction.customId !== "open-ticket") return;

        try {
            if (command) {
                await command.execute(interaction, client);
            } else {
                if (client.guilds.cache.get(interaction.guildId).channels.cache.find(c => c.topic == interaction.user.id)) {
                    return interaction.reply({
                        content: 'Έχετε ήδη δημιουργήσει ένα ticket! Δεν μπορείτε και δεύτερο για αποφυγή spam !',
                        ephemeral: true
                    });
                };


                if (interaction.values[0] == `${config.ticketoption1}`) {
                    console.log(interaction.user.id)
                    interaction.guild.channels.create(`ticket-${interaction.values[0]}-${interaction.user.tag}`, {
                        name: `ticket-${interaction.values[0]}-${interaction.user.username}`,
                        parent: config.parentOpened,
                        topic: interaction.user.id,
                        type: ChannelType.GuildText,
                        permissionOverwrites: [{
                            id: interaction.user.id,
                            allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                        },
                        {
                            id: config.ticketrole1,
                            allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
                        },
                        {
                            id: interaction.guild.roles.everyone,
                            deny: ['VIEW_CHANNEL'],
                        },
                        ],
                    }).then(async c => {
                        interaction.reply({
                            content: `To ticket δημιουργήθηκε στο κανάλι: <#${c.id}>`,
                            ephemeral: true
                        });

                        const embed = new EmbedBuilder()
                            .setColor('#429cf5')
                            .setAuthor({ name: 'Ticket', iconURL: `${config.serverlogo}` })
                            .setDescription(`<@!${interaction.user.id}> δημιουργήθηκε ένα ${interaction.values[0]} ticket!`)
                            .setFooter({ text: `${config.servername}`, iconURL: `${config.serverlogo}` })
                            .setTimestamp();

                        const row = new ActionRowBuilder()
                            .addComponents(
                                new ButtonBuilder()
                                    .setCustomId('close-ticket')
                                    .setLabel('Κλείστε το ticket σας !')
                                    .setEmoji(config.ticketcloseemoji)
                                    .setStyle(ButtonStyle.Danger),
                            );

                        const opened = await c.send({
                            content: `<@&${config.ticketrole1}>`,
                            embeds: [embed],
                            components: [row]
                        });

                        opened.pin().then(() => {
                            opened.channel.bulkDelete(1);
                        });
                    });
                };

Error:

632895760937123840
C:\Users\MariosWRLD\Desktop\Programming\Newwwwwwww\Slash v14\node_modules\@discordjs\rest\dist\index.js:933
        throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
              ^

DiscordAPIError[50035]: Invalid Form Body
name[BASE_TYPE_REQUIRED]: This field is required
    at SequentialHandler.runRequest (C:\Users\MariosWRLD\Desktop\Programming\Newwwwwwww\Slash v14\node_modules\@discordjs\rest\dist\index.js:933:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.queueRequest (C:\Users\MariosWRLD\Desktop\Programming\Newwwwwwww\Slash v14\node_modules\@discordjs\rest\dist\index.js:712:14)
    at async REST.request (C:\Users\MariosWRLD\Desktop\Programming\Newwwwwwww\Slash v14\node_modules\@discordjs\rest\dist\index.js:1321:22)
    at async GuildChannelManager.create (C:\Users\MariosWRLD\Desktop\Programming\Newwwwwwww\Slash v14\node_modules\discord.js\src\managers\GuildChannelManager.js:170:18) {
  rawError: {
    code: 50035,
    errors: {
      name: {
        _errors: [
          {
            code: 'BASE_TYPE_REQUIRED',
            message: 'This field is required'
          }
        ]
      }
    },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/guilds/1014637766484697088/channels',
  requestBody: {
    files: undefined,
    json: {
      name: undefined,
      topic: undefined,
      type: undefined,
      nsfw: undefined,
      bitrate: undefined,
      user_limit: undefined,
      parent_id: undefined,
      position: undefined,
      permission_overwrites: undefined,
      rate_limit_per_user: undefined,
      rtc_region: undefined,
      video_quality_mode: undefined,
      available_tags: undefined,
      default_reaction_emoji: undefined,
      default_auto_archive_duration: undefined,
      default_sort_order: undefined,
      default_forum_layout: undefined
    }
  }
}

I don't know what the error is. Can someone help?


Solution

  • In the latest versions of discord.js, channels.create takes a single options parameter. Providing a string as the first parameter will throw the error above so you should remove that:

    interaction.guild.channels.create({
      name: `ticket-${interaction.values[0]}-${interaction.user.username}`,
      parent: config.parentOpened,
      topic: interaction.user.id,
      type: ChannelType.GuildText,
      permissionOverwrites: [
        {
          id: interaction.user.id,
          allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
        },
        {
          id: config.ticketrole1,
          allow: ['SEND_MESSAGES', 'VIEW_CHANNEL'],
        },
        {
          id: interaction.guild.roles.everyone,
          deny: ['VIEW_CHANNEL'],
        },
      ],
    })