Skip to content

Commit

Permalink
Add server filter to custom commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Vankka committed Nov 17, 2024
1 parent 2614eaf commit e62302e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static CustomCommandConfig defaultHelloWorld() {

public List<OptionConfig> options = new ArrayList<>();

@Comment("The Discord server id to register this command in\n"
+ "Use 0 for all Discord servers, or -1 to make the command global")
public long serverId = 0;

@Comment("Only one of the constraints has to be true to allow execution")
public List<ConstraintConfig> constraints = new ArrayList<>(Collections.singletonList(new ConstraintConfig()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ public void reload(Consumer<DiscordSRVApi.ReloadResult> resultConsumer) {
);
}

commandBuilder.setGuildOnly(config.serverId >= 0);
commandBuilder.setGuildId(config.serverId > 0 ? config.serverId : null);

ExecutionHandler handler = new ExecutionHandler(config);
commandBuilder.setEventHandler(handler::accept);
DiscordCommand command = commandBuilder.build();
Expand Down

0 comments on commit e62302e

Please sign in to comment.