Search in sources :

Example 1 with GlobalSlashEvent

use of com.freya02.botcommands.api.application.slash.GlobalSlashEvent in project BotCommands by freya022.

the class ApplicationCommandsBuilder method processSlashCommand.

private void processSlashCommand(ApplicationCommand applicationCommand, Method method) {
    if (method.getAnnotation(JDASlashCommand.class).guildOnly()) {
        if (!ReflectionUtils.hasFirstParameter(method, GlobalSlashEvent.class) && !ReflectionUtils.hasFirstParameter(method, GuildSlashEvent.class))
            throw new IllegalArgumentException("Slash command at " + Utils.formatMethodShort(method) + " must have a GuildSlashEvent or GlobalSlashEvent as first parameter");
        if (!ReflectionUtils.hasFirstParameter(method, GuildSlashEvent.class)) {
            // If type is correct but guild specialization isn't used
            LOGGER.warn("Guild-only slash command {} uses GlobalSlashEvent, consider using GuildSlashEvent to remove warnings related to guild stuff's nullability", Utils.formatMethodShort(method));
        }
    } else {
        if (!ReflectionUtils.hasFirstParameter(method, GlobalSlashEvent.class))
            throw new IllegalArgumentException("Slash command at " + Utils.formatMethodShort(method) + " must have a GlobalSlashEvent as first parameter");
    }
    final SlashCommandInfo info = new SlashCommandInfo(context, applicationCommand, method);
    LOGGER.debug("Adding slash command path {} for method {}", info.getPath(), Utils.formatMethodShort(method));
    context.addSlashCommand(info);
}
Also used : SlashCommandInfo(com.freya02.botcommands.internal.application.slash.SlashCommandInfo) GuildSlashEvent(com.freya02.botcommands.api.application.slash.GuildSlashEvent) GlobalSlashEvent(com.freya02.botcommands.api.application.slash.GlobalSlashEvent) JDASlashCommand(com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)

Aggregations

GlobalSlashEvent (com.freya02.botcommands.api.application.slash.GlobalSlashEvent)1 GuildSlashEvent (com.freya02.botcommands.api.application.slash.GuildSlashEvent)1 JDASlashCommand (com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand)1 SlashCommandInfo (com.freya02.botcommands.internal.application.slash.SlashCommandInfo)1