8

I try to create a channel but i always have an error. I don't find how to fix it.

Don't pay attention to the "req[0]." in "code" it comes from the database, no link with the problem because it works in v13

"It looks like your post is mostly code; please add some more details." I don't know what can I have for more details. haha.

Sorry, English is not my native langage.

error :

        throw new DiscordAPIError.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 (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:293:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.queueRequest (/root/project/node_modules/@discordjs/rest/dist/lib/handlers/SequentialHandler.cjs:99:14)
    at async REST.request (/root/project/node_modules/@discordjs/rest/dist/lib/REST.cjs:52:22)
    at async GuildChannelManager.create (/root/new ascension/node_modules/discord.js/src/managers/GuildChannelManager.js:145: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/873350117124628552/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
    }
  }
}

Node.js v18.3.0

code :

action.guild.channels.create(`hello`, {
type: "GUILD_TEXT",
parent: cat[0].ID,
permissionOverwrites: [
{
id: bot.user.id,
allow: ['VIEW_CHANNEL', "MANAGE_CHANNELS"]
},
{
id: action.user.id,
allow: ["VIEW_CHANNEL"]
},
{
id: req[0].ID,
deny: ["VIEW_CHANNEL"]
},
{
id: staff[0].ID,
allow: ["VIEW_CHANNEL"]
}
            
]
})

1 Answer 1

9

You can't set the type of the channel using a string anymore, you have to use the new ChannelType enum. You can import it from the discord.js library, and once you've done that, creating a channel would look something like this:

guild.channels.create({
    name: "hello",
    type: ChannelType.GuildText,
    parent: cat[0].ID,
    // your permission overwrites or other options here
});

Also make sure that all of your arguments are being passed in only one object, and the name isn't a separate argument.

6
  • Ahh I'm dumb, I knew it... Thanks for your help. But the error is always the same : "BASE_TYPE_REQUIRED" Where did this come from?
    – Alexis S.
    Sep 24, 2022 at 22:42
  • Oh sorry, the code snippet was wrong. All of the options need to be passed into only one object. I edited my answer to reflect this
    – isaac.g
    Sep 24, 2022 at 23:11
  • @AlexisS. If an answer solves your problem, you should upvote and accept (the checkmark) it so others know that it worked.
    – kelsny
    Sep 24, 2022 at 23:39
  • @caTS Yes ! I accepted but i can't upvote without have 15 reputation
    – Alexis S.
    Sep 25, 2022 at 0:06
  • Do you define the guild value in imports or is that something else? Dec 21, 2022 at 18:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.