Channels
Fetch a channel, then delete or send. Create text, voice, category, or link channels. Edit overwrites.
Fetch the channel, then call methods on it: client.channels.fetch then channel.delete() / channel.send().
const channel = await client.channels.fetch(channelId);
await channel.delete();
if (channel.isTextBased()) await channel.send('hi');Text-based means guild text, guild voice, DMs, and notes. Category and link channels fail isTextBased() and throw INVALID_CHANNEL_TYPE on send.
From a message, resolve the channel (cache or REST):
const channel = await message.resolveChannel();
await channel.delete();message.channel is the cached text, voice, or DM channel, or null. Prefer that when it is already there. channel.toString() is <#id>. client.channels.delete(id) only evicts the cache; the API call is channel.delete().
Create
import { ChannelType } from '@fluxerjs/core';
const guild = await message.resolveGuild();
if (!guild) return;
const textChannel = await guild.createChannel({
type: ChannelType.GuildText,
name: 'general',
});Options are camelCase (parentId, rateLimitPerUser). Requires Manage Channels.
Voice (also text-capable):
const voice = await guild.createChannel({
type: ChannelType.GuildVoice,
name: 'Lounge',
});
await voice.send('VC chat is on.');Link channel (no send; stores an external URL):
const link = await guild.createChannel({
type: ChannelType.GuildLink,
name: 'website',
url: 'https://fluxer.js.org',
});
if (link.isLink()) console.log(link.url);Edit, slowmode, reorder
const channel = await client.channels.fetch(channelId);
if (channel.isGuild()) {
await channel.edit({
name: 'renamed-channel',
topic: 'New topic here',
parentId: categoryId,
rateLimitPerUser: 5,
});
if (channel.isTextBased()) await channel.setSlowmode(5);
}
await guild.setChannelPositions([
{ id: channelId1, position: 0 },
{ id: channelId2, position: 1, parentId: categoryId },
]);fetchRtcRegions() is user-account only. Bots receive AccessDeniedError.
Permission overwrites
import { OverwriteType, PermissionFlags } from '@fluxerjs/core';
if (!channel.isGuild()) return;
await channel.permissionOverwrites.edit(roleId, {
type: OverwriteType.Role,
deny: ['SendMessages'],
});
await channel.permissionOverwrites.edit(memberId, {
type: OverwriteType.Member,
allow: [PermissionFlags.ViewChannel, PermissionFlags.SendMessages],
deny: [PermissionFlags.MentionEveryone],
});
await channel.permissionOverwrites.delete(roleId);allow / deny accept a bitfield string or PermissionResolvable (flag names, arrays, bitfields). Requires Manage Roles. Check effective perms with member.permissionsIn(channel) (Permissions).
You can also pass permissionOverwrites on guild.createChannel / channel.edit.
Invites
createInvite / fetchInvites are on guild channels. Narrow with channel.isGuild().
const channel = message.channel ?? (await message.resolveChannel());
if (!channel.isGuild()) return;
const invite = await channel.createInvite({ maxAge: 86400, maxUses: 10 });
await message.reply(`Invite: ${invite.url}`);Roles live in Roles, not here. Content warnings: Content Warnings.
Quick reference
| Method | Purpose |
|---|---|
client.channels.fetch(id) | Load a channel, then call delete / send / edit |
message.resolveChannel() | Same channel as the message |
channel.isTextBased() | Guild text, guild voice, DMs, notes |
channel.isVoice() / channel.isLink() | Voice vs link |
channel.send() | Post in a text-based channel |
channel.delete() | Delete (or close a DM) |
guild.createChannel() | Create text, voice, category, or link |
channel.permissionOverwrites.edit() | Allow / deny a role or member |
channel.createInvite() | Invite with maxUses, maxAge |