Skip to content

Commit

Permalink
Correctly handle disabled intent in setEnabledIntents
Browse files Browse the repository at this point in the history
  • Loading branch information
MinnDevelopment committed Nov 4, 2024
1 parent 53272b6 commit d8ecf5a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
10 changes: 4 additions & 6 deletions src/main/java/net/dv8tion/jda/api/JDABuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ public JDABuilder setDisabledIntents(@Nullable Collection<GatewayIntent> intents
{
this.intents = GatewayIntent.ALL_INTENTS;
if (intents != null)
this.intents &= ~GatewayIntent.getRaw(intents);
this.intents = 1 | (GatewayIntent.ALL_INTENTS & ~GatewayIntent.getRaw(intents));
return this;
}

Expand Down Expand Up @@ -1646,7 +1646,7 @@ public JDABuilder setEnabledIntents(@Nonnull GatewayIntent intent, @Nonnull Gate
Checks.notNull(intent, "Intents");
Checks.noneNull(intents, "Intents");
EnumSet<GatewayIntent> set = EnumSet.of(intent, intents);
return setDisabledIntents(EnumSet.complementOf(set));
return setEnabledIntents(set);
}

/**
Expand All @@ -1673,11 +1673,9 @@ public JDABuilder setEnabledIntents(@Nonnull GatewayIntent intent, @Nonnull Gate
public JDABuilder setEnabledIntents(@Nullable Collection<GatewayIntent> intents)
{
if (intents == null || intents.isEmpty())
setDisabledIntents(EnumSet.allOf(GatewayIntent.class));
else if (intents instanceof EnumSet)
setDisabledIntents(EnumSet.complementOf((EnumSet<GatewayIntent>) intents));
this.intents = 1;
else
setDisabledIntents(EnumSet.complementOf(EnumSet.copyOf(intents)));
this.intents = 1 | GatewayIntent.getRaw(intents);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2018,7 +2018,7 @@ public DefaultShardManagerBuilder setDisabledIntents(@Nullable Collection<Gatewa
{
this.intents = GatewayIntent.ALL_INTENTS;
if (intents != null)
this.intents &= ~GatewayIntent.getRaw(intents);
this.intents = 1 | ~GatewayIntent.getRaw(intents);
return this;
}

Expand Down Expand Up @@ -2110,7 +2110,7 @@ public DefaultShardManagerBuilder setEnabledIntents(@Nonnull GatewayIntent inten
Checks.notNull(intent, "Intent");
Checks.noneNull(intents, "Intent");
EnumSet<GatewayIntent> set = EnumSet.of(intent, intents);
return setDisabledIntents(EnumSet.complementOf(set));
return setEnabledIntents(set);
}

/**
Expand All @@ -2137,11 +2137,9 @@ public DefaultShardManagerBuilder setEnabledIntents(@Nonnull GatewayIntent inten
public DefaultShardManagerBuilder setEnabledIntents(@Nullable Collection<GatewayIntent> intents)
{
if (intents == null || intents.isEmpty())
setDisabledIntents(EnumSet.allOf(GatewayIntent.class));
else if (intents instanceof EnumSet)
setDisabledIntents(EnumSet.complementOf((EnumSet<GatewayIntent>) intents));
this.intents = 1;
else
setDisabledIntents(EnumSet.complementOf(EnumSet.copyOf(intents)));
this.intents = 1 | GatewayIntent.getRaw(intents);
return this;
}

Expand Down

0 comments on commit d8ecf5a

Please sign in to comment.