Search in sources :

Example 1 with InteractionEvent

use of net.essentialsx.api.v2.services.discord.InteractionEvent in project Essentials by drtshock.

the class InteractionControllerImpl method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (event.getGuild() == null || event.getMember() == null || !commandMap.containsKey(event.getName())) {
        return;
    }
    final InteractionCommand command = commandMap.get(event.getName());
    if (command.isDisabled()) {
        event.reply(tl("discordErrorCommandDisabled")).setEphemeral(true).queue();
        return;
    }
    event.deferReply(command.isEphemeral()).queue(null, failure -> logger.log(Level.SEVERE, "Error while deferring Discord command", failure));
    final InteractionEvent interactionEvent = new InteractionEventImpl(event);
    if (!DiscordUtil.hasRoles(event.getMember(), jda.getSettings().getCommandSnowflakes(command.getName()))) {
        interactionEvent.reply(tl("noAccessCommand"));
        return;
    }
    jda.getPlugin().getEss().scheduleSyncDelayedTask(() -> command.onCommand(interactionEvent));
}
Also used : InteractionCommand(net.essentialsx.api.v2.services.discord.InteractionCommand) InteractionEvent(net.essentialsx.api.v2.services.discord.InteractionEvent)

Example 2 with InteractionEvent

use of net.essentialsx.api.v2.services.discord.InteractionEvent in project Essentials by EssentialsX.

the class InteractionControllerImpl method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    if (event.getGuild() == null || event.getMember() == null || !commandMap.containsKey(event.getName())) {
        return;
    }
    final InteractionCommand command = commandMap.get(event.getName());
    if (command.isDisabled()) {
        event.reply(tl("discordErrorCommandDisabled")).setEphemeral(true).queue();
        return;
    }
    event.deferReply(command.isEphemeral()).queue(null, failure -> logger.log(Level.SEVERE, "Error while deferring Discord command", failure));
    final InteractionEvent interactionEvent = new InteractionEventImpl(event);
    if (!DiscordUtil.hasRoles(event.getMember(), jda.getSettings().getCommandSnowflakes(command.getName()))) {
        interactionEvent.reply(tl("noAccessCommand"));
        return;
    }
    jda.getPlugin().getEss().scheduleSyncDelayedTask(() -> command.onCommand(interactionEvent));
}
Also used : InteractionCommand(net.essentialsx.api.v2.services.discord.InteractionCommand) InteractionEvent(net.essentialsx.api.v2.services.discord.InteractionEvent)

Aggregations

InteractionCommand (net.essentialsx.api.v2.services.discord.InteractionCommand)2 InteractionEvent (net.essentialsx.api.v2.services.discord.InteractionEvent)2