Skip to content

Channels

Create and manage channels, roles, and invites. Covers guild.createChannel(), channel.edit(), channel.createInvite(), guild.createRole(), and more.

Channels — Create

Use guild.createChannel() to create text (0), voice (2), category (4), or link (5) channels. Requires Manage Channels permission. Pass parent_id to put a channel under a category.

javascript
import { Client, Events } from '@erinjs/core';

const client = new Client({ intents: 0 });

client.on(Events.MessageCreate, async (message) => {
  if (!message.guildId || message.content !== '!createchannel') return;
  const guild = client.guilds.get(message.guildId) ?? await client.guilds.resolve(message.guildId);
  if (!guild) return;

  // Text channel (0), voice (2), category (4), link (5)
  const textChannel = await guild.createChannel({
    type: 0,
    name: 'general',
  });

  // Category, then voice channel under it
  const category = await guild.createChannel({
    type: 4,
    name: 'Voice Chats',
  });
  const voiceChannel = await guild.createChannel({
    type: 2,
    name: 'Lounge',
    parent_id: category.id,
    bitrate: 64000,
  });

  await message.reply(`Created ${textChannel.name} and ${voiceChannel.name} in ${category.name}`);
});

await client.login(process.env.ERIN_BOT_TOKEN);

Channels — Fetch and Edit

Use guild.fetchChannels() to load all guild channels. Use channel.edit() to rename, set topic, move to a category, set slowmode, or update permission overwrites.

javascript
const guild = client.guilds.get(guildId) ?? await client.guilds.resolve(guildId);
if (!guild) return;

const channels = await guild.fetchChannels();

// Edit a text channel
const channel = guild.channels.get(channelId);
if (channel) {
  await channel.edit({
    name: 'renamed-channel',
    topic: 'New topic here',
    parent_id: categoryId,        // Move under category
    rate_limit_per_user: 5,      // 5 second slowmode
    nsfw: false,
  });
}

Channels — Delete and Reorder

Use channel.delete() to remove a channel. Use guild.setChannelPositions() to reorder channels or move them between categories.

javascript
// Delete channel (silent: true skips system message)
await channel.delete();
await channel.delete({ silent: true });

// Reorder channels
await guild.setChannelPositions([
  { id: channelId1, position: 0 },
  { id: channelId2, position: 1, parent_id: categoryId },
]);

Channel Permission Overwrites

Use channel.editPermission() to add or update overwrites (type 0=role, 1=member). Use channel.deletePermission() to remove. Use resolvePermissionsToBitfield() for allow/deny bitfields.

javascript
import { resolvePermissionsToBitfield, PermissionFlags } from '@erinjs/core';

// Deny SendMessages for a role (type 0=role, 1=member)
await channel.editPermission(roleId, {
  type: 0,
  deny: resolvePermissionsToBitfield(['SendMessages']),
});

// Allow ViewChannel for a specific member
await channel.editPermission(userId, {
  type: 1,
  allow: resolvePermissionsToBitfield([PermissionFlags.ViewChannel]),
});

// Remove overwrite
await channel.deletePermission(roleId);

Roles — Quick Reference

Create roles with guild.createRole(), fetch with guild.fetchRoles() or guild.fetchRole(roleId). Add/remove with guild.addRoleToMember() / guild.removeRoleFromMember(). Reorder with guild.setRolePositions().

TIP

See the Roles guide for full examples, permission bitfields, and role.edit() / role.delete().

javascript
// See the Roles guide for full examples and permission bitfields.
const role = await guild.createRole({ name: 'Mod', permissions: ['KickMembers', 'BanMembers'] });
await guild.addRoleToMember(userId, role.id);
await guild.removeRoleFromMember(userId, role.id);
await guild.setRolePositions([{ id: role.id, position: 5 }]);

Invites

Use channel.createInvite() to create an invite. Use channel.fetchInvites() to list channel invites. Use invite.delete() to revoke. invite.url gives the full invite URL.

javascript
import { Client, Events } from '@erinjs/core';

const client = new Client({ intents: 0 });

client.on(Events.MessageCreate, async (message) => {
  if (!message.content.startsWith('!invite') || !message.guildId) return;
  const channel = message.channel;
  if (!channel?.createInvite) return;

  if (message.content === '!invite') {
    const invite = await channel.createInvite({
      max_age: 86400,    // 24 hours
      max_uses: 10,
      temporary: false,
    });
    await message.reply(`Invite: ${invite.url}`);
  }

  if (message.content === '!invitelist') {
    const invites = await channel.fetchInvites();
    const list = invites.map((i) => `${i.code} (${i.max_uses ?? '∞'} uses)`).join('\n');
    await message.reply(list || 'No invites.');
  }

  if (message.content.startsWith('!inviterevoke ')) {
    const code = message.content.slice(13).trim();
    const invites = await channel.fetchInvites();
    const inv = invites.find((i) => i.code === code);
    if (inv) {
      await inv.delete();
      await message.reply('Invite revoked.');
    }
  }
});

await client.login(process.env.ERIN_BOT_TOKEN);

Quick Reference

APIMethodPurpose
Channelsguild.createChannel()Create text, voice, category, or link channel
Channelsguild.fetchChannels()Fetch all guild channels
Channelschannel.edit()Rename, set topic, slowmode, parent, overwrites
Channelschannel.delete()Delete a channel
Channelsguild.setChannelPositions()Reorder or reparent channels
Channelschannel.editPermission()Add or update permission overwrite
Channelschannel.deletePermission()Remove permission overwrite
Rolesguild.createRole()Create a role
Rolesguild.addRoleToMember()Add role to member
Rolesguild.removeRoleFromMember()Remove role from member
Inviteschannel.createInvite()Create invite with max_uses, max_age
Inviteschannel.fetchInvites()List channel invites
Invitesinvite.delete()Revoke invite

Released under the Apache-2.0 License.