cmd.message.data
Fetches a specific piece of data from a message by specifying a type key. Covers embed fields, message metadata, author info, attachments, reactions, mentions, components, and Components V2 elements.
const { cmd } = require("syntx.js");
await cmd.message.data({ channel, messageID, type, index, name }, message);
Parameters
| Parameter | Type | Required | Description |
|---|
channel | string | Yes | ID of the channel that contains the target message. |
messageID | string | Yes | ID of the message to read data from. |
type | string | Yes | The piece of data to retrieve. See the type reference below. |
index | number | No | 0-based index used by types that return items from a list (e.g. fieldName, textDisplayAt). Defaults to 0. |
name | string | No | Field name used by fieldByName to locate an embed field by its title. |
message | discord.js Message | Interaction | Yes | The message or interaction context. |
Type reference
Embed
| Type | Returns | Description |
|---|
title | string | null | The embed title. |
description | string | null | The embed description. |
image | string | null | URL of the embed image. |
thumbnail | string | null | URL of the embed thumbnail. |
footer | string | null | The embed footer text. |
footerIcon | string | null | URL of the embed footer icon. |
author | string | null | The embed author name. |
authorIcon | string | null | URL of the embed author icon. |
authorURL | string | null | URL linked in the embed author name. |
titleURL | string | null | URL linked in the embed title. |
color | number | null | The embed color as a decimal integer. |
timestamp | string | null | The embed timestamp. |
embedCount | number | Total number of embeds in the message. |
fields | object[] | All embed fields as an array of { name, value, inline }. |
fieldName | string | null | Name of the embed field at position index. |
fieldValue | string | null | Value of the embed field at position index. |
fieldInline | boolean | null | Whether the embed field at position index is inline. |
fieldByName | object | null | The first embed field whose name matches the name parameter. |
fieldCount | number | Total number of fields in the first embed. |
| Type | Returns | Description |
|---|
content | string | null | The plain text content of the message. |
id | string | The message ID. |
channelId | string | ID of the channel the message was sent in. |
guildId | string | null | ID of the guild the message was sent in, if any. |
createdAt | string | ISO 8601 timestamp of when the message was created. |
editedAt | string | null | ISO 8601 timestamp of when the message was last edited. |
pinned | boolean | Whether the message is pinned. |
tts | boolean | Whether the message was sent with text-to-speech. |
messageType | number | The raw discord.js message type integer. |
flags | string[] | Array of message flag strings. |
Author
| Type | Returns | Description |
|---|
authorId | string | The author's user ID. |
authorUsername | string | The author's username. |
authorGlobalName | string | null | The author's global display name, if set. |
authorBot | boolean | Whether the author is a bot. |
authorAvatar | string | URL of the author's avatar at 1024px. |
Attachments
| Type | Returns | Description |
|---|
attachment | string[] | Array of attachment URLs. |
attachmentCount | number | Number of attachments. |
attachmentData | object[] | Array of full attachment objects: { id, name, url, proxyURL, size, contentType, width, height, spoiler }. |
Mentions
| Type | Returns | Description |
|---|
mentionedUsers | string[] | IDs of all mentioned users. |
mentionedRoles | string[] | IDs of all mentioned roles. |
mentionedChannels | string[] | IDs of all mentioned channels. |
mentionedEveryone | boolean | Whether @everyone or @here was mentioned. |
Reactions
| Type | Returns | Description |
|---|
reactions | object[] | Array of reaction objects: { emoji, count, me }. Custom emojis use the <:name:id> format. |
reactionCount | number | Number of distinct reactions on the message. |
Stickers
| Type | Returns | Description |
|---|
stickers | object[] | Array of sticker objects: { id, name, url }. |
Reply reference
| Type | Returns | Description |
|---|
reference | object | null | The full message reference object, if this is a reply. |
referenceId | string | null | The ID of the message being replied to. |
Components
| Type | Returns | Description |
|---|
isV2 | boolean | Whether the message uses Components V2. |
components | object[] | The raw component rows. |
componentCount | number | Number of top-level component rows. |
buttons | object[] | All buttons from all rows: { label, customId, style, emoji, url, disabled }. |
selectMenus | object[] | All select menus from all rows: { type, customId, placeholder, minValues, maxValues, disabled, options }. |
Components V2
| Type | Returns | Description |
|---|
textDisplays | string[] | Content of all TextDisplay components. |
textDisplayAt | string | null | Content of the TextDisplay at position index. |
mediaGallery | object[] | Items from all MediaGallery components: { url, description, spoiler }. |
fileComponents | object[] | All File components: { url, spoiler }. |
sections | object[] | All Section components: { components, accessory }. |
containers | object[] | All Container components: { accentColor, spoiler, components }. |
separators | object[] | All Separator components: { divider, spacing }. |
thumbnailComponents | object[] | All Thumbnail components: { url, description, spoiler }. |
Examples
Read an embed field
client.command({
name: "readfield",
content: async (message) => {
const value = await cmd.message.data(
{
channel: message.channel.id,
messageID: "MESSAGE_ID",
type: "fieldValue",
index: 0,
},
message
);
message.reply(`Field value: ${value}`);
},
});
client.command({
name: "listbuttons",
content: async (message) => {
const buttons = await cmd.message.data(
{
channel: message.channel.id,
messageID: "MESSAGE_ID",
type: "buttons",
},
message
);
const labels = buttons.map(b => b.label).join(", ");
message.reply(`Buttons found: ${labels}`);
},
});
Read message author info
client.command({
name: "author",
content: async (message) => {
const username = await cmd.message.data(
{
channel: message.channel.id,
messageID: "MESSAGE_ID",
type: "authorUsername",
},
message
);
message.reply(`Message was sent by: ${username}`);
},
});