slash commands

how can creat slash command with open popup(modal) ? pls
13 Replies
d.js toolkit
d.js toolkit7mo 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 docs7mo ago
:guide: Other Interactions: Modals read more
Marion Maréchal
const Discord = require('discord.js');

const BotClient = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
],
});

BotClient.once('ready', () => {
console.log('Bot en ligne !');
});

BotClient.on(Discord.Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'ping') {
// Create the modal
const modal = new Discord.ModalBuilder()
.setCustomId('myModal')
.setTitle('My Modal');

// Add components to modal

// Create the text input components
const favoriteColorInput = new Discord.TextInputBuilder()
.setCustomId('favoriteColorInput')
// The label is the prompt the user sees for this input
.setLabel("What's your favorite color?")
// Short means only a single line of text
.setStyle(TextInputStyle.Short);

const hobbiesInput = new Discord.TextInputBuilder()
.setCustomId('hobbiesInput')
.setLabel("What's some of your favorite hobbies?")
// Paragraph means multiple lines of text.
.setStyle(TextInputStyle.Paragraph);

// An action row only holds one text input,
// so you need one action row per text input.
const firstActionRow = new Discord.ActionRowBuilder().addComponents(favoriteColorInput);
const secondActionRow = new Discord.ActionRowBuilder().addComponents(hobbiesInput);

// Add inputs to the modal
modal.addComponents(firstActionRow, secondActionRow);

// Show the modal to the user
await interaction.showModal(modal);
}
});
const Discord = require('discord.js');

const BotClient = new Discord.Client({
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.MessageContent,
],
});

BotClient.once('ready', () => {
console.log('Bot en ligne !');
});

BotClient.on(Discord.Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;

if (interaction.commandName === 'ping') {
// Create the modal
const modal = new Discord.ModalBuilder()
.setCustomId('myModal')
.setTitle('My Modal');

// Add components to modal

// Create the text input components
const favoriteColorInput = new Discord.TextInputBuilder()
.setCustomId('favoriteColorInput')
// The label is the prompt the user sees for this input
.setLabel("What's your favorite color?")
// Short means only a single line of text
.setStyle(TextInputStyle.Short);

const hobbiesInput = new Discord.TextInputBuilder()
.setCustomId('hobbiesInput')
.setLabel("What's some of your favorite hobbies?")
// Paragraph means multiple lines of text.
.setStyle(TextInputStyle.Paragraph);

// An action row only holds one text input,
// so you need one action row per text input.
const firstActionRow = new Discord.ActionRowBuilder().addComponents(favoriteColorInput);
const secondActionRow = new Discord.ActionRowBuilder().addComponents(hobbiesInput);

// Add inputs to the modal
modal.addComponents(firstActionRow, secondActionRow);

// Show the modal to the user
await interaction.showModal(modal);
}
});
that don't work
d.js docs
d.js docs7mo ago
Suggestion for @Georgina: :guide: Creating Your Bot: Creating slash commands - Individual command files Create a new folder named commands, which is where you'll store all of your command files. You'll be using the SlashCommandBuilderopen in new window class to construct the command definitions. read more
snowyv4
snowyv47mo ago
forgot to hide 😭
d.js docs
d.js docs7mo ago
:guide: Creating Your Bot: Creating slash commands read more
snowyv4
snowyv47mo ago
thats the right one.
Marion Maréchal
i don't understand what i need add juste this ?
new Discord.SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!');
new Discord.SlashCommandBuilder()
.setName('ping')
.setDescription('Replies with Pong!');
because that don't work
snowyv4
snowyv47mo ago
you have to register your slash command.
d.js docs
d.js docs7mo ago
:guide: Creating Your Bot: Registering slash commands - Command registration read more
Marion Maréchal
Can you do the code to get the slash command pls? 'Cause I don't understand with the guide its going anywhere
snowyv4
snowyv47mo ago
client.on('ready', (c) => {
const command = new SlashCommandBuilder()
.setName('example')
.setDescription("example cmd")
client.application.commands.create(command)
});
client.on('ready', (c) => {
const command = new SlashCommandBuilder()
.setName('example')
.setDescription("example cmd")
client.application.commands.create(command)
});
client.on('interactionCreate', (interaction) => {
if(!interaction.isChatInputCommand()) return
if(interaction.commandName==='example) {
console.log('cmd done')
}})
client.on('interactionCreate', (interaction) => {
if(!interaction.isChatInputCommand()) return
if(interaction.commandName==='example) {
console.log('cmd done')
}})
Want results from more Discord servers?
Add your server