Components v2

IIs it already possible to use the components? I get an error all the time that my message is empty
12 Replies
d.js toolkit
d.js toolkit3mo ago
Nicoals Matheisen
Nicoals MatheisenOP3mo ago
Node v18.19.0 discord.js@14.22.1
b3ssel
b3ssel3mo ago
If you need guidance with components v2 you can check out the guide
d.js docs
d.js docs3mo ago
:guide: Popular Topics: Display Components read more
Nicoals Matheisen
Nicoals MatheisenOP3mo ago
const {
SlashCommandBuilder,
ComponentType,
ButtonBuilder,
ButtonStyle,
MessageFlags
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Replies with test'),

async execute(interaction) {
await interaction.reply({
flags: MessageFlags.IsComponentsV2,
layout: {
type: ComponentType.Layout,
children: [
{
type: ComponentType.TextDisplay,
text: '✅ Dies ist eine Test-Nachricht mit Components V2!'
},
{ type: ComponentType.Separator },
new ButtonBuilder()
.setCustomId('test_button')
.setLabel('Klick mich')
.setStyle(ButtonStyle.Primary)
.toJSON()
]
}
});
}
};
const {
SlashCommandBuilder,
ComponentType,
ButtonBuilder,
ButtonStyle,
MessageFlags
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Replies with test'),

async execute(interaction) {
await interaction.reply({
flags: MessageFlags.IsComponentsV2,
layout: {
type: ComponentType.Layout,
children: [
{
type: ComponentType.TextDisplay,
text: '✅ Dies ist eine Test-Nachricht mit Components V2!'
},
{ type: ComponentType.Separator },
new ButtonBuilder()
.setCustomId('test_button')
.setLabel('Klick mich')
.setStyle(ButtonStyle.Primary)
.toJSON()
]
}
});
}
};
b3ssel
b3ssel3mo ago
layout is nothing where did you get that from?? even Discord isn’t calling it like that
Nicoals Matheisen
Nicoals MatheisenOP3mo ago
I edit the examplwe from discordjs guides
b3ssel
b3ssel3mo ago
you sure?
Nicoals Matheisen
Nicoals MatheisenOP3mo ago
100%
b3ssel
b3ssel3mo ago
looks more like an AI generated answer to me oh okay well you should check the guide again everything is called components and not layout or children ComponentType.Layout doesn’t exist and please choose between JSON format or the use of builders mixing makes it hella confusing to read
Nicoals Matheisen
Nicoals MatheisenOP3mo ago
// commands/test.js
const {
SlashCommandBuilder,
ComponentType,
ButtonBuilder,
ButtonStyle,
MessageFlags
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Replies with test'),

async execute(interaction) {
await interaction.reply({
flags: MessageFlags.IsComponentsV2,
"components": [
{
"type": 10,
"content": "This is a message using the Text Display component"
}
]
});
}
};
// commands/test.js
const {
SlashCommandBuilder,
ComponentType,
ButtonBuilder,
ButtonStyle,
MessageFlags
} = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('test')
.setDescription('Replies with test'),

async execute(interaction) {
await interaction.reply({
flags: MessageFlags.IsComponentsV2,
"components": [
{
"type": 10,
"content": "This is a message using the Text Display component"
}
]
});
}
};
okeoooo sometimes to read the docs can help XD
d.js toolkit
d.js toolkit3mo ago
The thread owner has marked this issue as solved.

Did you find this page helpful?