discord-modal-collector
v2.3.2
Published
Modal collector for Discord.js library
Downloads
15
Maintainers
Readme
Discord.js Modal Collector
Import:
// CommonJS
const { ModalCollector } = require("discord-modal-collector");
// Es Module
import { ModalCollector } from "discord-modal-collector";
Usage:
| | Optional | Type | | ----------- | ------------ | ---------------------------------------------------------------------------------- | | channel | false | TextChannel | | options | true | Object |
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
Discord: Tavuk Döner#7528