How to create a embed, with button in middle and text below and above in a single message.

Sample:
No description
6 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
d.js docs
d.js docs5mo ago
guide suggestion for @King Tiger: :guide: Popular Topics: Display Components read more
King Tiger
King TigerOP5mo ago
const {
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
MessageFlags,
ContainerBuilder,
TextDisplayBuilder,
MediaGalleryBuilder,
MediaGalleryAttachmentBuilder, // This must be here
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deployrules')
.setDescription('Deploys the interactive server rules panel using Display Components.'),

async execute(interaction) {
await interaction.deferReply({ ephemeral: false });

const rulesContainer = new ContainerBuilder()
.setAccentColor(0x2B2D31); // Discord dark mode background color

// Line 38 (relative to this code block) where the error occurred
const bannerGallery = new MediaGalleryBuilder()
.addAttachments(
new MediaGalleryAttachmentBuilder('https://media.discordapp.net/attachments/742607866447396894/901070783919570974/unknown.png?ex=686864cf&is=6867134f&hm=7bb9d0eb3c088a83696381ecbc08d536056619ddccd4773e69f9672b6136c452&=&format=webp&quality=lossless&width=400&height=179') // *** REPLACE WITH YOUR ACTUAL BANNER IMAGE URL ***
);

rulesContainer.addChildren(bannerGallery);

const textAboveButtons = new TextDisplayBuilder()
.addParagraph('Like in a discord server, we have rules to ensure a positive experience for everyone. Please take a moment to read them.');

rulesContainer.addChildren(textAboveButtons);

const readRulesEN = new ButtonBuilder()
.setCustomId('read_rules_en')
.setLabel('Read the Rules')
.setStyle(ButtonStyle.Success)
.setEmoji('🇺🇸');

const readRulesCN = new ButtonBuilder()
.setCustomId('read_rules_cn')
.setLabel('阅读规则')
.setStyle(ButtonStyle.Success)
.setEmoji('🇨🇳');


const {
SlashCommandBuilder,
ActionRowBuilder,
ButtonBuilder,
ButtonStyle,
MessageFlags,
ContainerBuilder,
TextDisplayBuilder,
MediaGalleryBuilder,
MediaGalleryAttachmentBuilder, // This must be here
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('deployrules')
.setDescription('Deploys the interactive server rules panel using Display Components.'),

async execute(interaction) {
await interaction.deferReply({ ephemeral: false });

const rulesContainer = new ContainerBuilder()
.setAccentColor(0x2B2D31); // Discord dark mode background color

// Line 38 (relative to this code block) where the error occurred
const bannerGallery = new MediaGalleryBuilder()
.addAttachments(
new MediaGalleryAttachmentBuilder('https://media.discordapp.net/attachments/742607866447396894/901070783919570974/unknown.png?ex=686864cf&is=6867134f&hm=7bb9d0eb3c088a83696381ecbc08d536056619ddccd4773e69f9672b6136c452&=&format=webp&quality=lossless&width=400&height=179') // *** REPLACE WITH YOUR ACTUAL BANNER IMAGE URL ***
);

rulesContainer.addChildren(bannerGallery);

const textAboveButtons = new TextDisplayBuilder()
.addParagraph('Like in a discord server, we have rules to ensure a positive experience for everyone. Please take a moment to read them.');

rulesContainer.addChildren(textAboveButtons);

const readRulesEN = new ButtonBuilder()
.setCustomId('read_rules_en')
.setLabel('Read the Rules')
.setStyle(ButtonStyle.Success)
.setEmoji('🇺🇸');

const readRulesCN = new ButtonBuilder()
.setCustomId('read_rules_cn')
.setLabel('阅读规则')
.setStyle(ButtonStyle.Success)
.setEmoji('🇨🇳');



const readRulesTH = new ButtonBuilder()
.setCustomId('read_rules_th')
.setLabel('อ่านกฎเกณฑ์')
.setStyle(ButtonStyle.Success)
.setEmoji(':flag_th:');

const buttonRow = new ActionRowBuilder()
.addComponents(readRulesEN, readRulesCN, readRulesTH);

rulesContainer.addChildren(buttonRow);

const warningSystemText = new TextDisplayBuilder()
.addParagraph(':rotating_light: **Warning System & Punishments** :rotating_light:')
.addParagraph('To keep our community safe and enjoyable for everyone, we enforce strict rules against unruly and toxic behavior, including actions or reactions that promote negativity. Members who violate these rules will be punished accordingly, with consequences depending on the severity of the offense and repeat violations.');

const punishmentProgressionText = new TextDisplayBuilder()
.addParagraph(':scales: **Punishment Progression**')
.addParagraph('• :yellow_circle: 1st Offense: Mute for 6 or 24 hours†')
.addParagraph('• :red_circle: 2nd Offense: Kick from the server')
.addParagraph('• • :black_circle: 3rd Offense: Ban from the server for 30 days')
.addParagraph('†Depending on severity of the offense.');

rulesContainer.addChildren(warningSystemText, punishmentProgressionText);

await interaction.editReply({
components: [rulesContainer],
});
},
};

const readRulesTH = new ButtonBuilder()
.setCustomId('read_rules_th')
.setLabel('อ่านกฎเกณฑ์')
.setStyle(ButtonStyle.Success)
.setEmoji(':flag_th:');

const buttonRow = new ActionRowBuilder()
.addComponents(readRulesEN, readRulesCN, readRulesTH);

rulesContainer.addChildren(buttonRow);

const warningSystemText = new TextDisplayBuilder()
.addParagraph(':rotating_light: **Warning System & Punishments** :rotating_light:')
.addParagraph('To keep our community safe and enjoyable for everyone, we enforce strict rules against unruly and toxic behavior, including actions or reactions that promote negativity. Members who violate these rules will be punished accordingly, with consequences depending on the severity of the offense and repeat violations.');

const punishmentProgressionText = new TextDisplayBuilder()
.addParagraph(':scales: **Punishment Progression**')
.addParagraph('• :yellow_circle: 1st Offense: Mute for 6 or 24 hours†')
.addParagraph('• :red_circle: 2nd Offense: Kick from the server')
.addParagraph('• • :black_circle: 3rd Offense: Ban from the server for 30 days')
.addParagraph('†Depending on severity of the offense.');

rulesContainer.addChildren(warningSystemText, punishmentProgressionText);

await interaction.editReply({
components: [rulesContainer],
});
},
};
Getting Error; MediaGalleryAttachmentBuilder is not a constructor
Filou
Filou5mo ago
discord.builders – Discord Embed Builder
Use new components in your Discord webhooks
Use new Discord components in messages for free and stylize your server however your want.
Amgelo
Amgelo5mo ago
that whole code looks ai generated, almost no methods exist, only the ones from v1 components you can't ask an ai to do the code for you, not look at the docs, then ask us why it's not working
Thorminate
Thorminate5mo ago
yeah and the // *** REPLACE WITH YOUR ACTUAL BANNER IMAGE URL *** comment really point that out (if you skip the whole part of everything in the code is wrong)

Did you find this page helpful?