Skip to content

Channel

Channel wraps a Discord channel payload and exposes resource methods for sending messages and editing channel properties.

import { Channel } from "lunibee";

Every channel has a kind, a short name in place of the numeric type:

kind type Class
"text" 0 TextChannel
"dm", "group-dm" 1, 3 DMChannel
"voice" 2 VoiceChannel
"category" 4 CategoryChannel
"announcement" 5 NewsChannel
"thread" 10, 11, 12 ThreadChannel
"stage" 13 StageChannel
"directory" 14 Channel
"forum" 15 ForumChannel
"media" 16 MediaChannel
"unknown" anything else Channel

channel.is(...kinds) tells you whether it is one of them and narrows the type; channel.as(...kinds) returns it typed that way, or throws a TypeError that names both kinds.

const channel = await bot.channel(id).get();
if (channel.is("text", "announcement")) await channel.send({ content: "hi" }); // TextChannel | NewsChannel
const voice = await bot.channel(id).as("voice"); // VoiceChannel, or a clear error
switch (channel.kind) {
case "forum": case "media": /* … */ break;
}

channelKindOf(type) and channelTypesOf(kind) convert between the two, and ChannelEnum still holds the raw numbers that appear in payloads.

Property Type Description
id string Snowflake ID.
type number Channel type (see ChannelEnum).
name string | null | undefined Channel name.
guildId string | undefined Guild this channel belongs to.
topic string | null | undefined Channel topic.
parentId string | null | undefined Parent category ID.
nsfw boolean | undefined Whether the channel is age-restricted.
rateLimitPerUser number | undefined Slowmode in seconds.
position number | undefined Sorting position.
createdAt Date Timestamp derived from the snowflake.
createdTimestamp number The same, in milliseconds.
permissionOverwrites APIOverwrite[] Role and member overwrites (empty for DMs and when not sent).
kind ChannelKind | "unknown" See Kinds.
partial (0.3.2) boolean true for the placeholder message.channel gets when the channel is not cached: only id, guildId and a guessed type are known, and permissionOverwrites is empty because it was never sent. permissionsFor() returns null for it.

Sends a message to this channel. It takes a payload object ({ content }, not a bare string; bot.channel(id).send() takes either). Throws when the channel is not attached to a client.

const msg = await channel.send({ content: "Hello! 🐝" });
// With embeds and components:
await channel.send({
embeds: [embed],
components: [row],
});

sendMessage(options), the old alias of send(), was removed in 0.3.1.

Edits this channel’s properties. update(options) is an alias.

await channel.edit({ name: "support", topic: "Get help here." });

Changes only the channel name. An empty name throws a TypeError.

await channel.editName("general");

Changes only the channel topic. Pass null to clear it.

await channel.editTopic("Community announcements and updates.");
await channel.editTopic(null); // clears topic

Moves the channel to a different category. Pass null to remove the parent.

await channel.editParent(categoryId);
await channel.editParent(null);

Deletes this channel. reason is shown in the audit log.

await channel.delete("Archived");

isThread() / isTextBased() / isVoiceBased() / isDMBased()

Section titled “isThread() / isTextBased() / isVoiceBased() / isDMBased()”

Type checks on the numeric type: threads (10, 11, 12); channels that take messages (0, 1, 2, 3, 5, 10-13); voice and stage (2, 13); DMs and group DMs (1, 3).

Returns the Discord channel mention string. Automatically used in template literals.

console.log(`Check out ${channel}`); // → "Check out <#123456789>"

Create a support ticket channel

client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "ticket") return;
const user = interaction.user;
if (!user) return;
const guild = client.guilds.get(interaction.guildId!);
const channel = await client.channels.create(interaction.guildId!, {
name: `ticket-${user.id}`,
topic: `Support ticket for ${user.username}`,
type: 0, // text
parent_id: TICKET_CATEGORY_ID,
});
await channel.send({
content: `Welcome ${interaction.user}! Support will be with you shortly.`,
});
await interaction.reply({ content: `Ticket created: ${channel}`, ephemeral: true });
});

Rename a channel from a command

client.on("interactionCreate", async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== "rename") return;
const name = interaction.options.getString("name", true);
const channel = interaction.channelId ? client.channels.get(interaction.channelId) : undefined;
if (!channel) return interaction.reply({ content: "Channel not found.", ephemeral: true });
await channel.editName(name);
await interaction.reply({ content: `✅ Renamed to **${name}**` });
});

editPermissionOverwrite(targetId, changes, options?)

Section titled “editPermissionOverwrite(targetId, changes, options?)”

Changes some permissions of one role’s or member’s overwrite and keeps the rest (unlike permissionOverwrites(id).edit(), which replaces the whole overwrite). true allows, false denies, null resets to inherited. Pass type (0 role, 1 member) when the overwrite does not exist yet.

await channel.editPermissionOverwrite(userId, { ViewChannel: true, SendMessages: false }, { type: 1, reason: "Ticket locked" });

The manager form is client.channels.permissionOverwrites(channelId).update(id, { allow?, deny?, inherit? }, { type?, reason? }) with bitfields. It reads the cached overwrites and fetches the channel when they are unknown or the channel is partial, so an edit never replaces the real overwrites with the placeholder’s empty list.

send also accepts files (see Message).