Message
Message wraps a Discord message object and exposes resource methods to interact with it directly — no manager lookups required.
Import
Section titled “Import”import { Message } from "lunibee";import { Message } from "lunibee";Properties
Section titled “Properties”| Property | Type | Description |
|---|---|---|
id |
string |
Snowflake ID of the message. |
content |
string |
Text content of the message. |
author |
User |
The user who sent the message. |
channelId |
string |
ID of the channel this message belongs to. |
channel |
Channel |
The channel this message was sent in. |
guildId |
string | undefined |
Guild ID, if the message is in a guild. |
flags |
number |
Raw message flags bitfield. |
timestamp |
Date |
When the message was created. |
createdAt |
Date |
Alias for timestamp. |
createdTimestamp |
number |
Unix timestamp (ms) of creation. |
attachments |
APIAttachment[] |
File attachments on this message. |
embeds |
APIEmbed[] |
Embeds on this message. |
components |
APIMessageComponent[] |
Interactive components on this message. |
stickers |
APIStickerItem[] |
Stickers sent with the message (sticker_items). |
poll |
APIPoll | null |
The poll, when the message is one. Results arrive on messageUpdate. |
messageSnapshots |
APIMessageSnapshot[] |
For a forwarded message, a partial copy of the original (content, embeds, attachments, …). |
mentions |
User[] |
Users mentioned in this message. |
mentionRoles |
string[] |
Role IDs mentioned in this message. |
mentionEveryone |
boolean |
Whether @everyone or @here was used. |
pinned |
boolean |
Whether the message is pinned. |
type |
number |
Message type (0 = default, 19 = reply, etc.). |
reference |
APIMessageReference | undefined |
The message_reference (reply, forward or crosspost source). |
referencedMessage |
Message | null | undefined |
The replied-to message; null when Discord says it was deleted. |
member |
GuildMember | null |
The author as a guild member (see 0.2.1 below). |
Boolean Getters
Section titled “Boolean Getters”| Getter | Description |
|---|---|
isEphemeral |
true if the message is only visible to the recipient. |
isPinned |
true if the message is pinned. |
isSystemMessage |
true if this is a system message (join, boost, etc.). |
isCrosspost |
true if crossposted from an announcement channel. |
hasAttachments |
true if the message has file attachments. |
hasEmbeds |
true if the message has embeds. |
hasComponents |
true if the message has interactive components. |
embedsSuppressed |
true if link embeds are suppressed. |
Methods
Section titled “Methods”reply(options)
Section titled “reply(options)”client.on("messageCreate", async (message) => { if (message.content === "!hello") { await message.reply("Hello back! 👋"); // or with a full payload: await message.reply({ content: "Hello!", embeds: [embed] }); }});client.on("messageCreate", async (message) => { if (message.content === "!hello") { await message.reply("Hello back! 👋"); // or with a full payload: await message.reply({ content: "Hello!", embeds: [embed] }); }});edit(options)
Section titled “edit(options)”update(options) is an alias. toJSON() returns a plain-object snapshot of the fields.
const updated = await message.edit({ content: "Edited content!" });const updated = await message.edit({ content: "Edited content!" });delete(reason?) / pin(reason?) / unpin(reason?) / crosspost() / suppressEmbeds()
Section titled “delete(reason?) / pin(reason?) / unpin(reason?) / crosspost() / suppressEmbeds()”await message.delete();await message.pin();await message.unpin();await message.crosspost();await message.suppressEmbeds();react(emoji) / removeReaction(emoji, userId?) / removeAllReactions()
Section titled “react(emoji) / removeReaction(emoji, userId?) / removeAllReactions()”await message.react("👍");await message.react("lunibee:123456789"); // custom emoji: name:idawait message.removeReaction("👍"); // bot's ownawait message.removeReaction("👍", userId); // specific userawait message.removeAllReactions();await message.react("👍");await message.react("lunibee:123456789"); // custom emoji: name:idawait message.removeReaction("👍");await message.removeReaction("👍", userId);await message.removeAllReactions();Examples
Section titled “Examples”Log every message
client.on("messageCreate", (message) => { if (message.author.bot) return; console.log(`[${message.channelId}] ${message.author.username}: ${message.content}`);});client.on("messageCreate", (message) => { if (message.author.bot) return; console.log(`[${message.channelId}] ${message.author.username}: ${message.content}`);});Delete a message after 5 seconds
client.on("messageCreate", async (message) => { if (message.content === "!self-destruct") { const reply = await message.reply("💣 Self-destructing in 5 seconds..."); setTimeout(() => reply.delete(), 5000); }});client.on("messageCreate", async (message) => { if (message.content === "!self-destruct") { const reply = await message.reply("💣 Self-destructing in 5 seconds..."); setTimeout(() => reply.delete(), 5000); }});0.2.0 Additions
Section titled “0.2.0 Additions”- Messages are cached only with the client’s
messageCacheoption. channels.iterateMessages(channelId, { before?, limit? })pages history newest-first.channels.bulkDeleteMessages(channelId, ids)takes 1–100 IDs, removes duplicates, and throws for messages older than 14 days.- Polls:
channels.endPoll(channelId, messageId)andchannels.fetchPollVoters(channelId, messageId, answerId, { after?, limit? }).
0.2.1 Additions
Section titled “0.2.1 Additions”member: on guild messages from the Gateway, the author as aGuildMember(ornull). Itspermissionsare computed from the cached roles, so prefix commands can check permissions like slash commands do, and its actions (kick(),timeout()…) work. The client also keeps the cached member current from each message.- Files:
send,replyandeditacceptfiles: [{ name, data, contentType? }](datais aBlob, bytes or a string) and upload them. createComponentCollector(options?): collects clicks and picks on this message’s components. Options are theCollectoroptions pluscomponentType. It always ends: aftertime, or 15 minutes (an interaction token’s life) when neithertimenoridleis set.awaitComponent(options?): the next click or pick (rejects when time runs out).
const panel = await message.reply({ content: "Delete this?", components: [new CreateActionRow().addComponents( new CreateButton().setCustomId("yes").setLabel("Yes").setStyle(ButtonType.Danger), ).toJSON()],});try { const click = await panel.awaitComponent({ filter: (i) => i.user?.id === message.author.id, time: 30_000 }); await click.update({ content: "Deleted.", components: [] });} catch { await panel.edit({ content: "Timed out.", components: [] });}
await channel.send({ content: "Your transcript", files: [{ name: "transcript.html", data: html }] });