discord.js v14 create channel

Viewed 25

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 Answers

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.

Related