Search in sources :

Example 1 with Cooldown

use of me.TechsCode.TechDiscordBot.objects.Cooldown in project TechDiscordBot by TechsCode-Team.

the class ModulesManager method onSlashCommand.

@SubscribeEvent
public void onSlashCommand(SlashCommandEvent e) {
    CommandModule cmd = cmdModules.stream().filter(c -> c.getName().equalsIgnoreCase(e.getName())).findFirst().orElse(null);
    if (cmd == null || e.getMember() == null || e.getUser().isBot())
        return;
    if (cmd.getCooldown() > 0 && cmd.getCooldowns().containsKey(e.getMember().getId())) {
        Cooldown cooldown = cmd.getCooldowns().get(e.getMember().getId());
        if (cooldown.isCooldownRemaining()) {
            e.deferReply(true).queue();
            e.reply("**Woah there... slow down!** There's still **" + cooldown.getRemainingCooldown() + "** seconds left on your cooldown!").queue();
            return;
        }
        cmd.getCooldowns().remove(e.getMember().getId());
    }
    cmd.onCommand(e.getTextChannel(), e.getMember(), e);
}
Also used : Cooldown(me.TechsCode.TechDiscordBot.objects.Cooldown) SubscribeEvent(net.dv8tion.jda.api.hooks.SubscribeEvent)

Aggregations

Cooldown (me.TechsCode.TechDiscordBot.objects.Cooldown)1 SubscribeEvent (net.dv8tion.jda.api.hooks.SubscribeEvent)1