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.

JavaScript
const { cmd } = require("syntx.js");

await cmd.message.data({ channel, messageID, type, index, name }, message);

Parameters

ParameterTypeRequiredDescription
channelstringYesID of the channel that contains the target message.
messageIDstringYesID of the message to read data from.
typestringYesThe piece of data to retrieve. See the type reference below.
indexnumberNo0-based index used by types that return items from a list (e.g. fieldName, textDisplayAt). Defaults to 0.
namestringNoField name used by fieldByName to locate an embed field by its title.
messagediscord.js Message | InteractionYesThe message or interaction context.

Type reference

Embed

TypeReturnsDescription
titlestring | nullThe embed title.
descriptionstring | nullThe embed description.
imagestring | nullURL of the embed image.
thumbnailstring | nullURL of the embed thumbnail.
footerstring | nullThe embed footer text.
footerIconstring | nullURL of the embed footer icon.
authorstring | nullThe embed author name.
authorIconstring | nullURL of the embed author icon.
authorURLstring | nullURL linked in the embed author name.
titleURLstring | nullURL linked in the embed title.
colornumber | nullThe embed color as a decimal integer.
timestampstring | nullThe embed timestamp.
embedCountnumberTotal number of embeds in the message.
fieldsobject[]All embed fields as an array of { name, value, inline }.
fieldNamestring | nullName of the embed field at position index.
fieldValuestring | nullValue of the embed field at position index.
fieldInlineboolean | nullWhether the embed field at position index is inline.
fieldByNameobject | nullThe first embed field whose name matches the name parameter.
fieldCountnumberTotal number of fields in the first embed.

Message metadata

TypeReturnsDescription
contentstring | nullThe plain text content of the message.
idstringThe message ID.
channelIdstringID of the channel the message was sent in.
guildIdstring | nullID of the guild the message was sent in, if any.
createdAtstringISO 8601 timestamp of when the message was created.
editedAtstring | nullISO 8601 timestamp of when the message was last edited.
pinnedbooleanWhether the message is pinned.
ttsbooleanWhether the message was sent with text-to-speech.
messageTypenumberThe raw discord.js message type integer.
flagsstring[]Array of message flag strings.

Author

TypeReturnsDescription
authorIdstringThe author's user ID.
authorUsernamestringThe author's username.
authorGlobalNamestring | nullThe author's global display name, if set.
authorBotbooleanWhether the author is a bot.
authorAvatarstringURL of the author's avatar at 1024px.

Attachments

TypeReturnsDescription
attachmentstring[]Array of attachment URLs.
attachmentCountnumberNumber of attachments.
attachmentDataobject[]Array of full attachment objects: { id, name, url, proxyURL, size, contentType, width, height, spoiler }.

Mentions

TypeReturnsDescription
mentionedUsersstring[]IDs of all mentioned users.
mentionedRolesstring[]IDs of all mentioned roles.
mentionedChannelsstring[]IDs of all mentioned channels.
mentionedEveryonebooleanWhether @everyone or @here was mentioned.

Reactions

TypeReturnsDescription
reactionsobject[]Array of reaction objects: { emoji, count, me }. Custom emojis use the <:name:id> format.
reactionCountnumberNumber of distinct reactions on the message.

Stickers

TypeReturnsDescription
stickersobject[]Array of sticker objects: { id, name, url }.

Reply reference

TypeReturnsDescription
referenceobject | nullThe full message reference object, if this is a reply.
referenceIdstring | nullThe ID of the message being replied to.

Components

TypeReturnsDescription
isV2booleanWhether the message uses Components V2.
componentsobject[]The raw component rows.
componentCountnumberNumber of top-level component rows.
buttonsobject[]All buttons from all rows: { label, customId, style, emoji, url, disabled }.
selectMenusobject[]All select menus from all rows: { type, customId, placeholder, minValues, maxValues, disabled, options }.

Components V2

TypeReturnsDescription
textDisplaysstring[]Content of all TextDisplay components.
textDisplayAtstring | nullContent of the TextDisplay at position index.
mediaGalleryobject[]Items from all MediaGallery components: { url, description, spoiler }.
fileComponentsobject[]All File components: { url, spoiler }.
sectionsobject[]All Section components: { components, accessory }.
containersobject[]All Container components: { accentColor, spoiler, components }.
separatorsobject[]All Separator components: { divider, spacing }.
thumbnailComponentsobject[]All Thumbnail components: { url, description, spoiler }.

Examples

Read an embed field

JavaScript
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}`);
  },
});

Get all buttons from a message

JavaScript
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

JavaScript
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}`);
  },
});