Xehny
Xehny
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
That works perfectly, thank you very much for all your help
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
ComponentType,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("command")
.setDescription("Test command"),

async execute(interaction) {
const embed1 = new EmbedBuilder()
.setTitle("Embed 1")
.setColor("#e00000");

const embed2 = new EmbedBuilder()
.setTitle("Embed 2")
.setColor("#e00000");

const button1 = new ButtonBuilder()
.setCustomId("button1")
.setLabel("Button 1")
.setStyle(ButtonStyle.Primary);

const button2 = new ButtonBuilder()
.setCustomId("button2")
.setLabel("Button 2")
.setStyle(ButtonStyle.Primary);

const row1 = new ActionRowBuilder().addComponents(button2);

const row2 = new ActionRowBuilder().addComponents(button1);

const message = await interaction.reply({
embeds: [embed1],
components: [row1],
});

const collector = message.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 15000,
});

collector.on("collect", (i) => {
if (i.customId === "button1") {
message.edit({
embeds: [embed1],
components: [row1],
});
} else if (i.customId === "button2") {
message.edit({
embeds: [embed2],
components: [row2],
});
}
});
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
ComponentType,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("command")
.setDescription("Test command"),

async execute(interaction) {
const embed1 = new EmbedBuilder()
.setTitle("Embed 1")
.setColor("#e00000");

const embed2 = new EmbedBuilder()
.setTitle("Embed 2")
.setColor("#e00000");

const button1 = new ButtonBuilder()
.setCustomId("button1")
.setLabel("Button 1")
.setStyle(ButtonStyle.Primary);

const button2 = new ButtonBuilder()
.setCustomId("button2")
.setLabel("Button 2")
.setStyle(ButtonStyle.Primary);

const row1 = new ActionRowBuilder().addComponents(button2);

const row2 = new ActionRowBuilder().addComponents(button1);

const message = await interaction.reply({
embeds: [embed1],
components: [row1],
});

const collector = message.createMessageComponentCollector({
componentType: ComponentType.Button,
time: 15000,
});

collector.on("collect", (i) => {
if (i.customId === "button1") {
message.edit({
embeds: [embed1],
components: [row1],
});
} else if (i.customId === "button2") {
message.edit({
embeds: [embed2],
components: [row2],
});
}
});
},
};
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
I now have it swapping back and forth but each time I click the button it still says ... for 3s and interaction failed, makes me think I'm not "acknowledging" the interaction or something
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("command")
.setDescription("Test command"),

async execute(interaction) {
const embed1 = new EmbedBuilder()
.setTitle("Embed 1")
.setColor("#e00000");

const embed2 = new EmbedBuilder()
.setTitle("Embed 2")
.setColor("#e00000");

const button1 = new ButtonBuilder()
.setCustomId("button1")
.setLabel("Button 1")
.setStyle(ButtonStyle.Primary);

const button2 = new ButtonBuilder()
.setCustomId("button2")
.setLabel("Button 2")
.setStyle(ButtonStyle.Primary);

const row1 = new ActionRowBuilder().addComponents(button2);

const row2 = new ActionRowBuilder().addComponents(button1);

const response = await interaction.reply({
embeds: [embed1],
components: [row1],
});

const confirmation = await response.awaitMessageComponent();

await confirmation.update({
embeds: [embed2],
components: [row2],
});
},
};
const {
SlashCommandBuilder,
EmbedBuilder,
ButtonBuilder,
ButtonStyle,
ActionRowBuilder,
} = require("discord.js");

module.exports = {
data: new SlashCommandBuilder()
.setName("command")
.setDescription("Test command"),

async execute(interaction) {
const embed1 = new EmbedBuilder()
.setTitle("Embed 1")
.setColor("#e00000");

const embed2 = new EmbedBuilder()
.setTitle("Embed 2")
.setColor("#e00000");

const button1 = new ButtonBuilder()
.setCustomId("button1")
.setLabel("Button 1")
.setStyle(ButtonStyle.Primary);

const button2 = new ButtonBuilder()
.setCustomId("button2")
.setLabel("Button 2")
.setStyle(ButtonStyle.Primary);

const row1 = new ActionRowBuilder().addComponents(button2);

const row2 = new ActionRowBuilder().addComponents(button1);

const response = await interaction.reply({
embeds: [embed1],
components: [row1],
});

const confirmation = await response.awaitMessageComponent();

await confirmation.update({
embeds: [embed2],
components: [row2],
});
},
};
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
Here's the skeleton code of what I have currently
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
I've got the embed updating once but I'm not sure what I need to do so they can switch back and forth multiple times
16 replies
DIAdiscord.js - Imagine an app
Created by Xehny on 11/25/2023 in #djs-questions
How to swap between 3 embeds using buttons?
Yeah the part I am confused on is how to change the message to another embed once the button has been pressed
16 replies