Search in sources :

Example 1 with Button

use of net.dv8tion.jda.api.interactions.components.buttons.Button in project MMDBot by MinecraftModDevelopment.

the class PaginatedCommand method createScrollButtons.

/**
 * Create the row of Component interaction buttons.
 * <p>
 * Currently, this just creates a left and right arrow.
 * Left arrow scrolls back a page. Right arrow scrolls forward a page.
 *
 * @param start The quote number at the start of the current page.
 * @return A row of buttons to go back and forth by one page.
 */
private ItemComponent[] createScrollButtons(int start) {
    Button backward = Button.primary(listener.getButtonID() + "-" + start + "-prev", Emoji.fromUnicode("◀️")).asDisabled();
    Button forward = Button.primary(listener.getButtonID() + "-" + start + "-next", Emoji.fromUnicode("▶️")).asDisabled();
    if (start != 0) {
        backward = backward.asEnabled();
    }
    if (start + items_per_page < maximum) {
        forward = forward.asEnabled();
    }
    return new ItemComponent[] { backward, forward };
}
Also used : Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent)

Example 2 with Button

use of net.dv8tion.jda.api.interactions.components.buttons.Button in project BotCommands by freya022.

the class ChoiceMenu method putComponents.

@Override
protected void putComponents() {
    super.putComponents();
    final MenuPage<E> page = pages.get(this.page);
    final List<E> entries = page.entries();
    for (int i = 0; i < entries.size(); i++) {
        final E item = entries.get(i);
        final ButtonContent content = buttonContentSupplier.apply(item, i);
        final Button choiceButton = Components.primaryButton(event -> {
            this.cleanup(event.getContext());
            callback.accept(event, item);
        }).setConstraints(constraints).build(content);
        components.addComponents(1 + (i / 5), choiceButton);
    }
}
Also used : Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ButtonContent(com.freya02.botcommands.api.utils.ButtonContent)

Example 3 with Button

use of net.dv8tion.jda.api.interactions.components.buttons.Button in project MMDBot by MinecraftModDevelopment.

the class CmdDictionary method createScrollButtons.

private static ItemComponent[] createScrollButtons(int start, String word, int maximum) {
    Button backward = Button.primary(ButtonListener.BUTTON_ID + "-" + start + "-prev-" + word + "-" + maximum, Emoji.fromUnicode("◀️")).asDisabled();
    Button forward = Button.primary(ButtonListener.BUTTON_ID + "-" + start + "-next-" + word + "-" + maximum, Emoji.fromUnicode("▶️")).asDisabled();
    if (start != 0) {
        backward = backward.asEnabled();
    }
    if (start + 1 < maximum) {
        forward = forward.asEnabled();
    }
    return new ItemComponent[] { backward, forward };
}
Also used : Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ItemComponent(net.dv8tion.jda.api.interactions.components.ItemComponent)

Example 4 with Button

use of net.dv8tion.jda.api.interactions.components.buttons.Button in project HangmanDiscordBot by megoRU.

the class MessageInfoHelp method buildMessage.

public void buildMessage(String p, MessageChannel messageChannel, SlashCommandInteractionEvent event, String avatarUrl, String userIdLong, String name) {
    String avatar = null;
    if (avatarUrl == null) {
        avatar = "https://cdn.discordapp.com/avatars/754093698681274369/dc4b416065569253bc6323efb6296703.png";
    }
    if (avatarUrl != null) {
        avatar = avatarUrl;
    }
    EmbedBuilder info = new EmbedBuilder();
    info.setColor(0xa224db);
    info.setAuthor(name, null, avatar);
    info.addField("Warning", "On May 1, 2022, the bot will work only in private messages. " + "\nDiscord refused to provide Message Content.\n" + "From May 1, 2022, if the game is created through the guild, " + "\nthe bot will send a private message with game.", false);
    info.addField(jsonParsers.getLocale("messages_events_Prefix", userIdLong), jsonParsers.getLocale("messages_events_Changes_Prefix", userIdLong) + jsonParsers.getLocale("messages_events_Reset_Prefix", userIdLong), false);
    info.addField(jsonParsers.getLocale("messages_events_Language_Title", userIdLong), "`" + p + jsonParsers.getLocale("messages_events_Language", userIdLong) + "`" + p + jsonParsers.getLocale("messages_events_Game_Language", userIdLong), false);
    info.addField(jsonParsers.getLocale("messages_events_Title", userIdLong), "`" + p + jsonParsers.getLocale("messages_events_Start_Hangman", userIdLong) + "`" + p + jsonParsers.getLocale("messages_events_Stop_Hangman", userIdLong) + "`" + p + jsonParsers.getLocale("messages_events_Stats_Hangman", userIdLong) + "`" + p + jsonParsers.getLocale("messages_events_My_Stats_Hangman", userIdLong) + "`" + p + jsonParsers.getLocale("messages_events_All_Stats_Hangman", userIdLong), false);
    info.addField(jsonParsers.getLocale("help_delete_Title", userIdLong), "`" + p + jsonParsers.getLocale("help_delete", userIdLong), false);
    info.addField(jsonParsers.getLocale("messages_events_Links", userIdLong), jsonParsers.getLocale("messages_events_Site", userIdLong) + jsonParsers.getLocale("messages_events_Add_Me_To_Other_Guilds", userIdLong) + jsonParsers.getLocale("messages_events_Vote_For_This_Bot", userIdLong), false);
    info.addField(jsonParsers.getLocale("messages_events_Bot_Creator", userIdLong), jsonParsers.getLocale("messages_events_Bot_Creator_Url_Steam", userIdLong), false);
    List<Button> buttons = new ArrayList<>();
    buttons.add(Button.link("https://discord.gg/UrWG3R683d", "Support"));
    if (BotStartConfig.getMapLanguages().get(userIdLong) != null) {
        if (BotStartConfig.getMapLanguages().get(userIdLong).equals("eng")) {
            buttons.add(Button.secondary(Buttons.BUTTON_CHANGE_LANGUAGE.name(), "Сменить язык").withEmoji(Emoji.fromUnicode("U+1F1F7U+1F1FA")));
        } else {
            buttons.add(Button.secondary(Buttons.BUTTON_CHANGE_LANGUAGE.name(), "Change language").withEmoji(Emoji.fromUnicode("U+1F1ECU+1F1E7")));
        }
    } else {
        buttons.add(Button.secondary(Buttons.BUTTON_CHANGE_LANGUAGE.name(), "Сменить язык").withEmoji(Emoji.fromUnicode("U+1F1F7U+1F1FA")));
    }
    if (messageChannel != null) {
        SenderMessage.sendMessage(info, messageChannel, buttons);
    } else {
        SenderMessage.sendMessage(info, event, buttons);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) Button(net.dv8tion.jda.api.interactions.components.buttons.Button) ArrayList(java.util.ArrayList)

Aggregations

Button (net.dv8tion.jda.api.interactions.components.buttons.Button)4 ItemComponent (net.dv8tion.jda.api.interactions.components.ItemComponent)2 ButtonContent (com.freya02.botcommands.api.utils.ButtonContent)1 ArrayList (java.util.ArrayList)1 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)1