Skip to content

Instantly share code, notes, and snippets.

@iamnotacoder-djs
Created February 26, 2022 13:21
Show Gist options
  • Save iamnotacoder-djs/22693214d3363d3c3bc25cdbcfc8112e to your computer and use it in GitHub Desktop.
Save iamnotacoder-djs/22693214d3363d3c3bc25cdbcfc8112e to your computer and use it in GitHub Desktop.
Discord.js@13.6.0 Discord Modals
const { Client, Intents, MessageEmbed, MessageActionRow, MessageButton } = require('discord.js'),
client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES ] }),
dsModals = require('discord-modals'),
{ Modal, TextInputComponent, showModal } = require('discord-modals');
dsModals(client);
var config = {
token: "your bot token",
prefix: "/",
adminID: "admin id",
embed_color: "#ffffff"
};
client.login(config.token);
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async (message) => {
if (!message.content.startsWith(config.prefix)) return;
const args = message.content.slice(config.prefix.length).trim().split(/ +/g);
const command = args.shift();
if (command == "modal") {
message.guild.commands.set([
{
name: "modal",
description: "modal slash command",
options: []
}
]);
}
});
client.on('interactionCreate', async (interaction) => {
if (interaction.isCommand()) {
if (interaction.commandName == "modal") {
const modal = new Modal()
.setCustomId(`modal-customid`)
.setTitle('Тест Модальных окон!')
.addComponents([
new TextInputComponent()
.setCustomId('textinput-customid1')
.setLabel('Текст в одну строку')
.setStyle('SHORT')
.setMinLength(4)
.setMaxLength(10)
.setPlaceholder('Введи какой-нибудь текст [4-100]')
.setRequired(true),
new TextInputComponent()
.setCustomId('textinput-customid2')
.setLabel('Многострочный текст')
.setStyle('LONG')
.setMinLength(4)
.setMaxLength(300)
.setPlaceholder('Введи какой-нибудь текст [4-300]')
.setRequired(true)
].slice(0, 5))
showModal(modal, {
client: client,
interaction: interaction
})
}
}
});
client.on('modalSubmit', (modal) => {
const firstResponse1 = modal.getTextInputValue('textinput-customid1') ?? "error";
const firstResponse2 = modal.getTextInputValue('textinput-customid2') ?? "error";
modal.reply(`Спасибо за заполнение формы! \`\`\`${firstResponse1}\`\`\`\`\`\`${firstResponse2}\`\`\``);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment