cmd.channel.create

Creates a new channel in the guild. Supports text, voice, forum, announcement, and category channels, with optional permission overwrites.

JavaScript
const { cmd } = require("syntx.js");

await cmd.channel.create({ data, permissions, returnID }, message);

Parameters

ParameterTypeRequiredDescription
dataobjectYesChannel configuration. See data fields below.
permissionsPermissionEntry[]NoPermission overwrites to apply. See permissions below.
returnIDbooleanNoIf true, returns the new channel's ID instead of the channel object. Defaults to false.
messagediscord.js MessageYesA guild message or interaction, used to access the guild.

Data fields

FieldTypeRequiredDescription
namestringYesThe name of the channel.
typestringNoChannel type: "text", "voice", "forum", "ad", or "category". Defaults to "text".
topicstringNoThe channel topic or description. Not available for categories.
nsfwbooleanNoWhether the channel is age-restricted. Not available for categories. Defaults to false.
cooldownnumberNoSlowmode duration in seconds. Not available for categories.
categorystringNoID of the parent category. Not available when creating a category itself.
positionnumberNoPosition of the channel in the sidebar.
reasonstringNoAudit log reason for the action.

Note

The "ad" type creates an announcement channel (also known as a news channel). The fields topic, nsfw, cooldown, category, and position are not allowed when type is "category".

Permissions

Each entry in the permissions array must have the following shape:

FieldTypeRequiredDescription
idstringYesThe user or role ID to target. Use "everyone" to target @everyone.
typestringYesEither "user" or "role".
permissionsobjectYesA map of Discord permission names to true (allow) or false (deny).

Permission names follow Discord's naming convention, such as "SEND_MESSAGES", "VIEW_CHANNEL", "MANAGE_MESSAGES", etc.

Returns

discord.js Channel | string

Returns the created channel object by default. If returnID is true, returns the channel ID as a string instead.

Examples

Create a basic text channel

JavaScript
client.command({
  name: "createchannel",
  content: async (message) => {
    const channel = await cmd.channel.create(
      {
        data: {
          name: "general",
          topic: "Talk about anything",
          nsfw: false,
        },
      },
      message
    );

    message.reply(`Channel created: <#${channel.id}>`);
  },
});

Create a channel with permission overwrites

JavaScript
client.command({
  name: "privatechannel",
  content: async (message) => {
    const id = await cmd.channel.create(
      {
        data: {
          name: "staff-only",
          type: "text",
          reason: "Staff channel setup",
        },
        permissions: [
          {
            id: "everyone",
            type: "role",
            permissions: {
              VIEW_CHANNEL: false,
            },
          },
          {
            id: "STAFF_ROLE_ID",
            type: "role",
            permissions: {
              VIEW_CHANNEL: true,
              SEND_MESSAGES: true,
            },
          },
        ],
        returnID: true,
      },
      message
    );

    message.reply(`Staff channel created with ID: ${id}`);
  },
});

Create a category channel

JavaScript
client.command({
  name: "createcategory",
  content: async (message) => {
    const category = await cmd.channel.create(
      {
        data: {
          name: "Community",
          type: "category",
          position: 0,
        },
      },
      message
    );

    message.reply(`Category created: ${category.name}`);
  },
});

Warning

The bot must have the Manage Channels permission in the guild for this function to work. If the permission is missing, a SyntxError is thrown.