Coder Social home page Coder Social logo

seailz / modalapi Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 335 KB

ModalAPI lets you interact with JDA modals with ease.

Home Page: https://www.seailz.com

License: GNU General Public License v3.0

Java 100.00%
discord discord-bot discord-java jda jda-bot jda-utilities modal jda-modals modal-api

modalapi's Introduction

ModalAPI

ModalAPI lets you interact with JDA & Discord modals with ease. Here's an example of how to make a modal:

QUICK DISCALIMER

You must include this line in your main class:

        jdaInstanceVariable.addEventListener(new ModalListener());

If you don't, it will not work. I may try to find a way around this in the future, but for now, that's how it is.

public class ModalExample extends Modal {

    public ModalExample() {
        super("Questions", "age-question"); // The title and the ID
        TextInput input = TextInput.create("age", "How old are you?", TextInputStyle.SHORT)
                .setMaxLength(2).build(); // The input fields

        addComponent(member -> input); // adds the component to the modal
        onSubmit((member, mappings, event) -> {
            event.reply("Thanks for submitting your age! We received **" + mappings[0].getAsString() + "** years old.").queue();
        }); // what to do when the modal is submitted
    }
}

Here's an example of opening a modal for a user:

public class ModalCommand extends ListenerAdapter {

    @Override
    public void onSlashCommandInteraction(@NotNull SlashCommandInteractionEvent event) {
        if (!event.getName().equals("modal"))
            return;
        ModalExample testModal = new ModalExample();
        testModal.open(event.getMember(), event);
    }

}

If you want to use this API, you can use Maven or Gradle to add it to your project:

Maven:

<repository>
    <id>jitpack.io</id>
	<url>https://jitpack.io</url>
</repository>
<dependency>
    <groupId>com.github.seailz</groupId>
	<artifactId>modalapi</artifactId>
	<version>v1.0</version>
</dependency>

Gradle:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
	dependencies {
	        implementation 'com.github.seailz:modalapi:Tag'
	}

modalapi's People

Contributors

seailz avatar

Stargazers

 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.