i tried modals but it doesnt work

i got a few errors before then fixed them but now the modals dont work. and ı was following the guide, did i do something wrong? the error i was getting the "client is not defined" but now ı have fixed it
18 Replies
d.js toolkit
d.js toolkit2mo 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! - Marked as resolved by OP
Yido
Yido2mo ago
const {Client, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, GatewayIntentBits } = require('discord.js');

const Discord = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });



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

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

// Add components to modal

// Create the text input components
const favoriteColorInput = new 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 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 ActionRowBuilder().addComponents(favoriteColorInput);
const secondActionRow = new ActionRowBuilder().addComponents(hobbiesInput);

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

// Show the modal to the user
await interaction.showModal(modal);
}
});
const {Client, ActionRowBuilder, Events, ModalBuilder, TextInputBuilder, TextInputStyle, GatewayIntentBits } = require('discord.js');

const Discord = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });



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

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

// Add components to modal

// Create the text input components
const favoriteColorInput = new 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 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 ActionRowBuilder().addComponents(favoriteColorInput);
const secondActionRow = new ActionRowBuilder().addComponents(hobbiesInput);

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

// Show the modal to the user
await interaction.showModal(modal);
}
});
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
i think yes but when i delete one of them the code gives the same "client is not defined" error
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs2mo ago
:guide: Creating Your Bot: Event handling read more
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
i have followed everything in the event handler guide (maybe did not read all of it) can you give me a example i still dont understand what should ı do
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
i created the event holder and also have putted the code inside index.js
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
i still did not understand how am ı gonna solve this problem is it explained in the part you provided
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
now it works! so all ı had to do was use module.exports?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
is it possible to run the code with only execute(client) and without module.exports?
Unknown User
Unknown User2mo ago
Message Not Public
Sign In & Join Server To View
Yido
Yido2mo ago
okays thank you for everything