Git Product home page Git Product logo

discord.js-v13-modal-handler's Introduction

To get started make a new file in your handler file or wherever you wish this to be.

Paste this code below into said file

const { resolve } = require('path');
const { readdir } = require('fs').promises;
const chalk = require('chalk');
module.exports = (client) => {
  
  async function getFiles(dir) {
    const dirents = await readdir(dir, { withFileTypes: true });
    const files = await Promise.all(dirents.map((dirent) => {
      const res = resolve(dir, dirent.name);
      return dirent.isDirectory() ? getFiles(res) : res;
    }));
    return Array.prototype.concat(...files);
  }
  
  async function run(){
      const files = await getFiles("./Modals/");
      const jsFiles = files.filter((f) => f.split(`.`).pop() === "js")
      if (jsFiles.length <= 0)
         return console.log(chalk.yellowBright.bold(`[Modal-Handler] No loadable Modals detected`));
          console.log(chalk.blueBright.bold(`[Modal-Handler]: Loaded ${jsFiles.length} Modals`))
      jsFiles.forEach((fileName, index) => {
          let props = require(fileName);
          client.interactions.set(props.help.custom_id, props);
      });
  }
  run();

  client.on(`interactionCreate`, async (interaction) => {
    if (interaction.isModalSubmit()) {
      var cmd = client.interactions.get(interaction.customId);
      if (cmd) cmd.run(client, interaction);
    }
  });
};

After this is done go to your main file (normally index.js) and paste this somewhere

require(./Handlers/Modals)(client);

Make sure to change ./Handlers/Modals to the path where you have it

Once done make a new folder in your main directory named Modals and then make folders/files for each modal all you need to do is add your modals customID into there and the code to be executed once triggered

To use this

module.exports.run = async (client, interaction) => {

            //the code to be executed goes here

}
module.exports.help = {
  custom_id: `customID goes here`,
};

discord.js-v13-modal-handler's People

Contributors

clappy8 avatar

Stargazers

francis avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.