Coder Social home page Coder Social logo

ice-games / java-discord-framework Goto Github PK

View Code? Open in Web Editor NEW
4.0 1.0 0.0 470 KB

Designed to make developing bots faster and simpler!

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

License: GNU General Public License v3.0

Java 100.00%
bot bot-discord bot-framework discord discord-bot discord-framework discord-java framework java java-bot

java-discord-framework's Introduction

NOTE: This project will not continue to be updated.
However, I'm working on my own Discord API library that implements many of the same designs and features of JDF.
See here: http://i.slz.lol/go/lxKLxA

Java-Discord-Framework

Designed to make developing bots faster and simpler!

Maven

<repository>
	<id>jitpack.io</id>
	<url>https://jitpack.io</url>
</repository>
<dependency>
	<groupId>com.github.ice-games</groupId>
	<artifactId>java-discord-framework</artifactId>
	<version>1.4</version>
</dependency>

Setting up your main class

In your main class, you need to extend DiscordBot, like this:

import javax.security.auth.login.LoginException;

public class BotExample extends DiscordBot {

    public BotExample() throws LoginException, InterruptedException {
        super("token");
        registerCommands(new CommandExample());
        build();
        getJda().awaitReady();
    }
}

Commands

Making commands with this framework is really easy, here's an example:

import com.seailz.jdaframework.command.Command;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;

@CommandInfo(
  name = "epiccommand",
  description = "This is such an epic command!"
)
public class CommandExample extends Command {
    @Override
    public void onCommand(SlashCommandInteractionEvent e) {
        e.reply("Hello World!").queue();
    }
}

See? Really easy! Now all you need to do is register it in your main class, like this:

registerCommands(
    new CommandExample()
);

Context Menus

Message Context Menus

public class MessageContextMenuExample extends ContextMenu {

    public MessageContextMenuExample() {
        super("Context Menu", Command.Type.MESSAGE);
        onSubmitMessage(e -> {
            e.reply("Hello World!").queue();
        });

        // Just call a new instance of this class after your build method in your bot class
    }

}

In your main class, all you need to do is call a new instance of this class, like this:

new MessageContextMenuExample();

User context menus

The same as before, but just replace onSubmitMessage, with onSubmitUser.

Modals

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);
    }

}

Buttons

ButtonManager.listen(Button.secondary("epic-button", "Don't you agree?"), event -> {
       event.reply("You clicked the epic button!").queue();
});

java-discord-framework's People

Contributors

dependabot[bot] avatar seailz avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

java-discord-framework's Issues

[Feature Request] move away from lombok

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

image

Example Use-Case

No response

[Feature Request] Select Menus

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

Allows for more easier use of select menus

Example Use-Case

No response

[Feature Request] Database Util

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

Reminder for me to copy the code of this repo https://github.com/seailz/Database4J into this framework

Example Use-Case

No response

[Feature Request] AutoComplete support

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

autocomplete

Example Use-Case

public EpicCommand() {
  setAutoComplete(optionIndex, member -> {
     if (member.getEffectiveName().equals(“seailz”) return List.of(“a”, “b”, “c”,
  });
}

[Feature Request] Button Framework

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

Allows for easier use of buttons, without having to have multiple events.

Example Use-Case

No response

[Feature Request] Buttons to keep their actions on restart

General Troubleshooting

  • I have checked for similar issues on the Issue-tracker.
  • I have updated to the latest Framework version
  • I have checked the branches or the maintainers' PRs for upcoming features.

Feature Request

Example Use-Case

No response

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.