diff --git a/src/examples/java/SlashBotExample.java b/src/examples/java/SlashBotExample.java index fec4195a4c..629174e928 100644 --- a/src/examples/java/SlashBotExample.java +++ b/src/examples/java/SlashBotExample.java @@ -33,6 +33,7 @@ import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction; import java.util.EnumSet; +import java.util.concurrent.TimeUnit; import static net.dv8tion.jda.api.interactions.commands.OptionType.*; @@ -170,10 +171,10 @@ public void ban(SlashCommandInteractionEvent event, User user, Member member) OptionMapping::getAsString); // used if getOption("reason") is not null (provided) // Ban the user and send a success response - event.getGuild().ban(user, delDays, reason) - .reason(reason) // audit-log reason - .flatMap(v -> hook.sendMessage("Banned user " + user.getAsTag())) - .queue(); + event.getGuild().ban(user, delDays, TimeUnit.DAYS) + .reason(reason) // audit-log ban reason (sets X-AuditLog-Reason header) + .flatMap(v -> hook.sendMessage("Banned user " + user.getAsTag())) // chain a followup message after the ban is executed + .queue(); // execute the entire call chain } public void say(SlashCommandInteractionEvent event, String content) diff --git a/src/main/java/net/dv8tion/jda/api/entities/Guild.java b/src/main/java/net/dv8tion/jda/api/entities/Guild.java index d94e7fc73c..46b11af8f7 100644 --- a/src/main/java/net/dv8tion/jda/api/entities/Guild.java +++ b/src/main/java/net/dv8tion/jda/api/entities/Guild.java @@ -15,6 +15,9 @@ */ package net.dv8tion.jda.api.entities; +import net.dv8tion.jda.annotations.DeprecatedSince; +import net.dv8tion.jda.annotations.ForRemoval; +import net.dv8tion.jda.annotations.ReplaceWith; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.Region; @@ -57,6 +60,9 @@ import net.dv8tion.jda.internal.utils.Helpers; import net.dv8tion.jda.internal.utils.concurrent.task.GatewayTask; +import javax.annotation.CheckReturnValue; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.time.Duration; import java.time.temporal.TemporalAccessor; import java.util.*; @@ -65,10 +71,6 @@ import java.util.function.Consumer; import java.util.function.Predicate; -import javax.annotation.CheckReturnValue; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; - /** * Represents a Discord {@link net.dv8tion.jda.api.entities.Guild Guild}. * This should contain all information provided from Discord about a Guild. @@ -538,7 +540,6 @@ default ImageProxy getIcon() *
* List of Features
*
- *
* @return Never-null, unmodifiable Set containing all of the Guild's features.
*/
@Nonnull
@@ -1895,7 +1896,7 @@ default RestAction Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
@@ -1917,7 +1918,7 @@ default RestAction Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link RestAction RestAction} include the following:
@@ -3182,10 +3183,20 @@ default AuditableRestAction You can unban a user with {@link net.dv8tion.jda.api.entities.Guild#unban(UserSnowflake) Guild.unban(UserReference)}.
*
@@ -3234,6 +3243,20 @@ default AuditableRestAction Examples Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
* the returned {@link RestAction RestAction} include the following:
* You can unban a user with {@link net.dv8tion.jda.api.entities.Guild#unban(UserSnowflake) Guild.unban(UserReference)}.
- *
- * Note: {@link net.dv8tion.jda.api.entities.Guild#getMembers()} will still contain the
- * {@link net.dv8tion.jda.api.entities.Member Member} until Discord sends the
- * {@link net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent GuildMemberRemoveEvent}.
- *
- * Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
- * the returned {@link RestAction RestAction} include the following:
- * You can unban a user with {@link net.dv8tion.jda.api.entities.Guild#unban(UserSnowflake) Guild.unban(UserSnowflake)}.
*
@@ -453,59 +457,14 @@ default ImageProxy getEffectiveAvatar()
* You can unban a user with {@link net.dv8tion.jda.api.entities.Guild#unban(UserSnowflake) Guild.unban(UserSnowflake)}.
- *
- * Note: {@link net.dv8tion.jda.api.entities.Guild#getMembers()} will still contain the
- * {@link net.dv8tion.jda.api.entities.Member Member} until Discord sends the
- * {@link net.dv8tion.jda.api.events.guild.member.GuildMemberRemoveEvent GuildMemberRemoveEvent}.
- *
- * Possible {@link net.dv8tion.jda.api.requests.ErrorResponse ErrorResponses} caused by
- * the returned {@link net.dv8tion.jda.api.requests.RestAction RestAction} include the following:
- * Reasons for any AuditableRestAction may be retrieved
* via {@link net.dv8tion.jda.api.audit.AuditLogEntry#getReason() AuditLogEntry.getReason()}
* in iterable {@link AuditLogPaginationAction AuditLogPaginationActions}
* from {@link net.dv8tion.jda.api.entities.Guild#retrieveAuditLogs() Guild.retrieveAuditLogs()}!
+ * For {@link net.dv8tion.jda.api.entities.Guild#ban(UserSnowflake, int, TimeUnit) guild bans}, this is also accessible via {@link Guild.Ban#getReason()}.
*
* This will specify the reason via the {@code X-Audit-Log-Reason} Request Header.
- *
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int)} or
+ *
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int, TimeUnit)} or
* {@link #unban(UserSnowflake)}.
*
*
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int)} or {@link #unban(UserSnowflake)}.
+ *
If you wish to ban or unban a user, use either {@link #ban(UserSnowflake, int, TimeUnit)} or {@link #unban(UserSnowflake)}.
*
*
If you wish to ban a user without deleting any messages, provide delDays with a value of 0.
+ * Bans the user specified by the provided {@link UserSnowflake} and deletes messages sent by the user based on the {@code deletionTimeframe}.
+ *
If you wish to ban a user without deleting any messages, provide {@code deletionTimeframe} with a value of 0.
+ * To set a ban reason, use {@link AuditableRestAction#reason(String)}.
*
*
+ * Banning a user without deleting any messages:
+ * {@code
+ * guild.ban(user, 0, TimeUnit.SECONDS)
+ * .reason("Banned for rude behavior")
+ * .queue();
+ * }
+ * Banning a user and deleting messages from the past hour:
+ * {@code
+ * guild.ban(user, 1, TimeUnit.HOURS)
+ * .reason("Banned for spamming")
+ * .queue();
+ * }
+ *
*
@@ -3247,10 +3270,10 @@ default AuditableRestAction
*
* @param user
diff --git a/src/main/java/net/dv8tion/jda/api/entities/Member.java b/src/main/java/net/dv8tion/jda/api/entities/Member.java
index 27fe4df977..838e943d14 100644
--- a/src/main/java/net/dv8tion/jda/api/entities/Member.java
+++ b/src/main/java/net/dv8tion/jda/api/entities/Member.java
@@ -16,7 +16,10 @@
package net.dv8tion.jda.api.entities;
+import net.dv8tion.jda.annotations.DeprecatedSince;
+import net.dv8tion.jda.annotations.ForRemoval;
import net.dv8tion.jda.annotations.Incubating;
+import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.OnlineStatus;
import net.dv8tion.jda.api.entities.channel.unions.DefaultGuildChannelUnion;
@@ -439,7 +442,8 @@ default ImageProxy getEffectiveAvatar()
/**
* Bans this Member and deletes messages sent by the user based on the amount of delDays.
- *
See {@link Member#canInteract(Member)}
* @throws java.lang.IllegalArgumentException
*
- *
*
- * @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
- */
- @Nonnull
- @CheckReturnValue
- AuditableRestAction
If you wish to ban a member without deleting any messages, provide delDays with a value of 0.
- *
- *
- *
- *
- * @param user
- * The {@link UserSnowflake} for the user to ban.
- * This can be a member or user instance or {@link User#fromId(long)}.
- * @param delDays
- * The history of messages, in days, that will be deleted.
- *
- * @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
- * If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#BAN_MEMBERS} permission.
- * @throws net.dv8tion.jda.api.exceptions.HierarchyException
- * If the logged in account cannot ban the other user due to permission hierarchy position.
- *
The target Member cannot be banned due to a permission discrepancy
The specified User does not exit
See {@link Member#canInteract(Member)}
- * @throws java.lang.IllegalArgumentException
- *
- *
+ * @return {@link AuditableRestAction}
*
- * @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
+ * @see AuditableRestAction#reason(String)
*/
@Nonnull
@CheckReturnValue
- default AuditableRestAction
The target Member cannot be unbanned due to a permission discrepancy
*
*
The specified User is invalid
The specified User does not exist
*
If you wish to ban a member without deleting any messages, provide delDays with a value of 0.
+ *
If you wish to ban a user without deleting any messages, provide {@code deletionTimeframe} with a value of 0.
+ * To set a ban reason, use {@link AuditableRestAction#reason(String)}.
*
*
The target Member cannot be banned due to a permission discrepancy
The specified Member was removed from the Guild before finishing the task
The user no longer exists
See {@link Member#canInteract(Member)}
- * @throws java.lang.IllegalArgumentException
- *
- *
- *
- * @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
- *
- * @since 4.0.0
- */
- @Nonnull
- @CheckReturnValue
- default AuditableRestAction
If you wish to ban a member without deleting any messages, provide delDays with a value of 0.
- *
- *
- *
- *
- * @param delDays
- * The history of messages, in days, that will be deleted.
- * @param reason
- * The reason for this action or {@code null} if there is no specified reason
+ * @param deletionTimeframe
+ * The timeframe for the history of messages that will be deleted. (seconds precision)
+ * @param unit
+ * Timeframe unit as a {@link TimeUnit} (for example {@code member.ban(7, TimeUnit.DAYS)}).
*
* @throws net.dv8tion.jda.api.exceptions.InsufficientPermissionException
* If the logged in account does not have the {@link net.dv8tion.jda.api.Permission#BAN_MEMBERS} permission.
@@ -514,21 +473,21 @@ default AuditableRestAction
The target Member cannot be banned due to a permission discrepancy
The specified Member was removed from the Guild before finishing the task
See {@link Member#canInteract(Member)}
* @throws java.lang.IllegalArgumentException
*
- *
*
+ * @return {@link AuditableRestAction}
*
- * @return {@link net.dv8tion.jda.api.requests.restaction.AuditableRestAction AuditableRestAction}
- *
- * @since 4.0.0
+ * @see Guild#ban(UserSnowflake, int, TimeUnit)
+ * @see AuditableRestAction#reason(String)
*/
@Nonnull
@CheckReturnValue
- default AuditableRestAction
When the provided reason is empty or {@code null} it will be treated as not set.
+ * If the provided reason is longer than {@value #MAX_REASON_LENGTH} characters, it will be truncated to fit the limit.
*
*
Using methods with a reason parameter will always work and override this header.
- * (ct. {@link net.dv8tion.jda.api.entities.Guild#ban(UserSnowflake, int, String) Guild.ban(UserSnowflake, int, String)})
*
* @param reason
- * The reason for this action which should be logged in the Guild's AuditLogs
+ * The reason for this action which should be logged in the Guild's AuditLogs (up to {@value #MAX_REASON_LENGTH} characters)
*
* @return The current AuditableRestAction instance for chaining convenience
*
diff --git a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
index 3e5a016648..0f87c99947 100644
--- a/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
+++ b/src/main/java/net/dv8tion/jda/internal/entities/GuildImpl.java
@@ -86,6 +86,7 @@
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
@@ -1383,7 +1384,7 @@ public AuditableRestAction