cmd.message.send

Sends a message to a channel. Works with both prefix commands and slash command interactions, and supports text, embeds, components, files, polls, and Components V2 layouts.

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

await cmd.message.send({ text, channel, components, embeds, files, poll, returnId, ephemeral, options }, message);

Parameters

ParameterTypeRequiredDescription
textstring | objectNoThe message text. Can also be an object with content and embeds keys.
channelstringNoID of the channel to send to. Defaults to the current channel.
componentsarrayNoAn array of component rows (buttons, select menus, Display components, etc.).
embedsobject[]NoArray of raw discord.js embed objects.
filesarrayNoArray of file attachments.
pollPoll | objectNoA Poll instance or a raw Discord poll object to attach.
returnIdbooleanNoIf true, returns the sent message's ID instead of null. Defaults to false.
ephemeralbooleanNoIf true, sends the message as ephemeral (interactions only). Defaults to false.
optionsobjectNoSend behavior flags. See options below.
messagediscord.js Message | InteractionYesThe message or interaction context.

Options

FieldTypeDefaultDescription
replybooleanfalseReply to the interaction instead of editing.
followUpbooleanfalseSend a follow-up to the interaction.
updatebooleanfalseUpdate the original interaction message.
pingbooleantrueWhether to ping the user when replying. Set to false to reply silently.
v2booleanfalseForce Components V2 mode. This is automatically enabled when V2 component types are detected.
silentbooleanfalseSuppresses the notification for the sent message.

Components V2

When v2 is true, or when the components array contains V2 component types (such as TextDisplay, MediaGallery, Section, etc.), the message is sent in Components V2 mode. In this mode:

  • text must be empty or absent.
  • embeds cannot be used.
  • poll cannot be used.
  • At least one Display component must be present.

Returns

string | null : If returnId is true, returns the sent message's ID. Otherwise returns null.

Examples

Send a simple text message

JavaScript
client.command({
  name: "hello",
  content: async (message) => {
    await cmd.message.send({ text: "Hello, world!" }, message);
  },
});

Send to a different channel

JavaScript
client.command({
  name: "announce",
  content: async (message) => {
    await cmd.message.send(
      {
        text: "An important announcement!",
        channel: "ANNOUNCEMENT_CHANNEL_ID",
      },
      message
    );
  },
});

Send with an embed

JavaScript
client.command({
  name: "info",
  content: async (message) => {
    const embed = new Embed()
    embed.set({
        title: "Server Info",
        description: "Welcome to the server!"
    })

    await cmd.message.send(
      {
        embeds: [embed.build()],
      },
      message
    );
  },
});

Send an ephemeral reply (interactions only)

JavaScript
client.slash({
  data: new SlashCommand({ name: "secret", description: "Only you can see this" }),
  execute: async (interaction) => {
    await cmd.message.send(
      {
        text: "This is only visible to you.",
        ephemeral: true,
        options: { reply: true },
      },
      interaction
    );
  },
});

Send and get the message ID

JavaScript
client.command({
  name: "track",
  content: async (message) => {
    const id = await cmd.message.send(
      {
        text: "This message is being tracked.",
        returnId: true,
      },
      message
    );

    console.log(`Sent message ID: ${id}`);
  },
});

Warning

ephemeral only works in slash command interactions. Using it in a prefix command context will throw a SyntxError.