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
| Parameter | Type | Required | Description |
|---|---|---|---|
text | string | object | No | The message text. Can also be an object with content and embeds keys. |
channel | string | No | ID of the channel to send to. Defaults to the current channel. |
components | array | No | An array of component rows (buttons, select menus, Display components, etc.). |
embeds | object[] | No | Array of raw discord.js embed objects. |
files | array | No | Array of file attachments. |
poll | Poll | object | No | A Poll instance or a raw Discord poll object to attach. |
returnId | boolean | No | If true, returns the sent message's ID instead of null. Defaults to false. |
ephemeral | boolean | No | If true, sends the message as ephemeral (interactions only). Defaults to false. |
options | object | No | Send behavior flags. See options below. |
message | discord.js Message | Interaction | Yes | The message or interaction context. |
Options
| Field | Type | Default | Description |
|---|---|---|---|
reply | boolean | false | Reply to the interaction instead of editing. |
followUp | boolean | false | Send a follow-up to the interaction. |
update | boolean | false | Update the original interaction message. |
ping | boolean | true | Whether to ping the user when replying. Set to false to reply silently. |
v2 | boolean | false | Force Components V2 mode. This is automatically enabled when V2 component types are detected. |
silent | boolean | false | Suppresses 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:
textmust be empty or absent.embedscannot be used.pollcannot 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.