Channel
Channel wraps a Discord channel payload and exposes resource methods for sending messages and editing channel properties.
Import
Section titled “Import”import { Channel } from "lunibee";import { Channel } from "lunibee";Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
id |
string |
Snowflake ID. |
type |
number |
Channel type (see ChannelType). |
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. |
Methods
Section titled “Methods”send(options) / sendMessage(options)
Section titled “send(options) / sendMessage(options)”Sends a message to this channel.
const msg = await channel.send({ content: "Hello! 🐝" });
// With embeds and components:await channel.send({ embeds: [embed], components: [row],});const msg = await channel.send({ content: "Hello 🐝" });
// With embeds and components:await channel.send({ embeds: [embed], components: [row],});edit(options)
Section titled “edit(options)”Edits this channel’s properties.
await channel.edit({ name: "support", topic: "Get help here." });await channel.edit({ name: "support", topic: "Get help here." });editName(name)
Section titled “editName(name)”Changes only the channel name.
await channel.editName("general");await channel.editName("general");editTopic(topic)
Section titled “editTopic(topic)”Changes only the channel topic. Pass null to clear it.
await channel.editTopic("Community announcements and updates.");await channel.editTopic(null); // clears topicawait channel.editTopic("Community announcements and updates.");await channel.editTopic(null); // clears topiceditParent(parentId)
Section titled “editParent(parentId)”Moves the channel to a different category. Pass null to remove the parent.
await channel.editParent(categoryId);await channel.editParent(null);await channel.editParent(categoryId);await channel.editParent(null);delete()
Section titled “delete()”Deletes this channel.
await channel.delete();await channel.delete();toString()
Section titled “toString()”Returns the Discord channel mention string. Automatically used in template literals.
console.log(`Check out ${channel}`); // → "Check out <#123456789>"console.log(`Check out ${channel}`); // → "Check out <#123456789>"Examples
Section titled “Examples”Create a support ticket channel
client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "ticket") return;
const guild = client.guilds.get(interaction.guildId!); const channel = await client.channels.create(interaction.guildId!, { name: `ticket-${interaction.user.id}`, topic: `Support ticket for ${interaction.user.username}`, 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 });});client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "ticket") return;
const guild = client.guilds.get(interaction.guildId); const channel = await client.channels.create(interaction.guildId, { name: `ticket-${interaction.user.id}`, topic: `Support ticket for ${interaction.user.username}`, parent_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 = client.channels.get(interaction.channelId); if (!channel) return interaction.reply({ content: "Channel not found.", ephemeral: true }); await channel.editName(name); await interaction.reply({ content: `✅ Renamed to **${name}**` });});client.on("interactionCreate", async (interaction) => { if (!interaction.isChatInputCommand() || interaction.commandName !== "rename") return; const name = interaction.options.getString("name", true); const channel = client.channels.get(interaction.channelId); if (!channel) return interaction.reply({ content: "Channel not found.", ephemeral: true }); await channel.editName(name); await interaction.reply({ content: `✅ Renamed to **${name}**` });});