Skip to content

Message

Message wraps a Discord message object and exposes resource methods to interact with it directly — no manager lookups required.

import { Message } from "lunibee";
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).
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.
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] });
}
});

update(options) is an alias. toJSON() returns a plain-object snapshot of the fields.

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:id
await message.removeReaction("👍"); // bot's own
await message.removeReaction("👍", userId); // specific user
await message.removeAllReactions();

Log every message

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);
}
});
  • Messages are cached only with the client’s messageCache option.
  • 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) and channels.fetchPollVoters(channelId, messageId, answerId, { after?, limit? }).
  • member: on guild messages from the Gateway, the author as a GuildMember (or null). Its permissions are 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, reply and edit accept files: [{ name, data, contentType? }] (data is a Blob, bytes or a string) and upload them.
  • createComponentCollector(options?): collects clicks and picks on this message’s components. Options are the Collector options plus componentType. It always ends: after time, or 15 minutes (an interaction token’s life) when neither time nor idle is 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 }] });