2.3.2 • Published 2 years ago

discord-modal-collector v2.3.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

Discord.js Modal Collector

Import:

// CommonJS
const { ModalCollector } = require("discord-modal-collector");

// Es Module
import { ModalCollector } from "discord-modal-collector";

Usage:

OptionalType
channelfalseTextChannel
optionstrueObject
const collector = new ModalCollector(channel, options);

or

const collector = interaction.createModalCollector(options);

Important Warning! If you want to use it like this, you need to import it in your main file.

Warning: Channel parameter is not used here!

Example:

const {
	Client,
	Intents: { FLAGS },
	MessageActionRow,
	TextInputComponent,
	Modal,
} = require("discord.js");
const client = new Client({ intents: Object.keys(FLAGS) });
require("discord-modal-collector");

client.on("ready", () => {
	console.log(client.user.tag);
	console.log();
});

client.on("interactionCreate", async (interaction) => {
	if (interaction.commandName === "test") {
		await interaction.showModal(
			new Modal()
				.setCustomId("modal")
				.setTitle("Modal Test")
				.addComponents(
					new MessageActionRow().addComponents(
						new TextInputComponent()
							.setCustomId("text_input")
							.setLabel("Text Input")
							.setValue("Hello World!")
							.setPlaceholder("Placeholder")
							.setStyle("SHORT")
							.setRequired(true)
					)
				)
		);

		const collector = interaction.createModalCollector({
			filter: (i) => i.customId === "modal",
		});

		collector.on("collect", (modal) => {
			console.log(modal.fields.getTextInputComponent("text_input"));
			collector.stop();
		});
	}
});

client.login("your_secret_token");

Contact

Tavuk Döner#7528 Discord: Tavuk Döner#7528