diff --git a/src/main/java/net/dv8tion/jda/api/interactions/commands/Command.java b/src/main/java/net/dv8tion/jda/api/interactions/commands/Command.java
index 530793385d..8f2b1e8157 100644
--- a/src/main/java/net/dv8tion/jda/api/interactions/commands/Command.java
+++ b/src/main/java/net/dv8tion/jda/api/interactions/commands/Command.java
@@ -228,6 +228,15 @@ default OffsetDateTime getTimeModified()
*/
boolean isGuildOnly();
+ /**
+ * Whether this command is restricted to NSFW (age-restricted) channels.
+ *
+ * @return True, if this command is NSFW
+ *
+ * @see Age-Restricted Commands FAQ
+ */
+ boolean isNSFW();
+
/**
* Possible command types
*/
diff --git a/src/main/java/net/dv8tion/jda/api/interactions/commands/build/CommandData.java b/src/main/java/net/dv8tion/jda/api/interactions/commands/build/CommandData.java
index 9ee84f2d92..29b8e4910a 100644
--- a/src/main/java/net/dv8tion/jda/api/interactions/commands/build/CommandData.java
+++ b/src/main/java/net/dv8tion/jda/api/interactions/commands/build/CommandData.java
@@ -146,6 +146,22 @@ public interface CommandData extends SerializableData
@Nonnull
CommandData setGuildOnly(boolean guildOnly);
+ /**
+ * Sets whether this command should only be usable in NSFW (age-restricted) channels.
+ *
Default: false
+ *
+ *
Note: Age-restricted commands will not show up in direct messages by default unless the user enables them in their settings.
+ *
+ * @param nsfw
+ * True, to make this command nsfw
+ *
+ * @return The builder instance, for chaining
+ *
+ * @see Age-Restricted Commands FAQ
+ */
+ @Nonnull
+ CommandData setNSFW(boolean nsfw);
+
/**
* The current command name
*
@@ -190,6 +206,15 @@ public interface CommandData extends SerializableData
*/
boolean isGuildOnly();
+ /**
+ * Whether this command should only be usable in NSFW (age-restricted) channels
+ *
+ * @return True, if this command is restricted to NSFW channels
+ *
+ * @see Age-Restricted Commands FAQ
+ */
+ boolean isNSFW();
+
/**
* Converts the provided {@link Command} into a CommandData instance.
*
@@ -212,6 +237,7 @@ static CommandData fromCommand(@Nonnull Command command)
final CommandDataImpl data = new CommandDataImpl(command.getType(), command.getName());
return data.setDefaultPermissions(command.getDefaultPermissions())
.setGuildOnly(command.isGuildOnly())
+ .setNSFW(command.isNSFW())
.setNameLocalizations(command.getNameLocalizations().toMap())
.setDescriptionLocalizations(command.getDescriptionLocalizations().toMap());
}
@@ -252,6 +278,7 @@ static CommandData fromData(@Nonnull DataObject object)
}
data.setGuildOnly(!object.getBoolean("dm_permission", true));
+ data.setNSFW(object.getBoolean("nsfw"));
data.setNameLocalizations(LocalizationUtils.mapFromProperty(object, "name_localizations"));
data.setDescriptionLocalizations(LocalizationUtils.mapFromProperty(object, "description_localizations"));
return data;
diff --git a/src/main/java/net/dv8tion/jda/api/interactions/commands/build/SlashCommandData.java b/src/main/java/net/dv8tion/jda/api/interactions/commands/build/SlashCommandData.java
index 7c1d0bbee4..700283dbe4 100644
--- a/src/main/java/net/dv8tion/jda/api/interactions/commands/build/SlashCommandData.java
+++ b/src/main/java/net/dv8tion/jda/api/interactions/commands/build/SlashCommandData.java
@@ -63,6 +63,10 @@ public interface SlashCommandData extends CommandData
@Override
SlashCommandData setGuildOnly(boolean guildOnly);
+ @Nonnull
+ @Override
+ SlashCommandData setNSFW(boolean nsfw);
+
/**
* Configure the description
*
@@ -405,6 +409,7 @@ static SlashCommandData fromCommand(@Nonnull Command command)
CommandDataImpl data = new CommandDataImpl(command.getName(), command.getDescription());
data.setGuildOnly(command.isGuildOnly());
+ data.setNSFW(command.isNSFW());
data.setDefaultPermissions(command.getDefaultPermissions());
//Command localizations are unmodifiable, make a copy
data.setNameLocalizations(command.getNameLocalizations().toMap());
@@ -454,6 +459,7 @@ static SlashCommandData fromData(@Nonnull DataObject object)
DataArray options = object.optArray("options").orElseGet(DataArray::empty);
CommandDataImpl command = new CommandDataImpl(name, description);
command.setGuildOnly(!object.getBoolean("dm_permission", true));
+ command.setNSFW(object.getBoolean("nsfw"));
command.setDefaultPermissions(
object.isNull("default_member_permissions")
diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandCreateAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandCreateAction.java
index 683d88569d..a55b648810 100644
--- a/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandCreateAction.java
+++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandCreateAction.java
@@ -168,4 +168,8 @@ default CommandCreateAction addSubcommandGroups(@Nonnull Collection extends Su
@Override
@CheckReturnValue
CommandCreateAction setGuildOnly(boolean guildOnly);
+
+ @Nonnull
+ @Override
+ CommandCreateAction setNSFW(boolean nsfw);
}
diff --git a/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandEditAction.java b/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandEditAction.java
index 02d4566d05..8261eb90c2 100644
--- a/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandEditAction.java
+++ b/src/main/java/net/dv8tion/jda/api/requests/restaction/CommandEditAction.java
@@ -101,6 +101,23 @@ public interface CommandEditAction extends RestAction Note: Age-restricted commands will not show up in direct messages by default unless the user enables them in their settings.
+ *
+ * @param nsfw
+ * True, to make this command nsfw
+ *
+ * @return The CommandEditAction instance, for chaining
+ *
+ * @see Age-Restricted Commands FAQ
+ */
+ @Nonnull
+ @CheckReturnValue
+ CommandEditAction setNSFW(boolean nsfw);
+
/**
* Sets the {@link net.dv8tion.jda.api.Permission Permissions} that a user must have in a specific channel to be able to use this command.
*
Default: false
+ *
+ *
By default, everyone can use this command ({@link DefaultMemberPermissions#ENABLED}). Additionally, a command can be disabled for everyone but admins via {@link DefaultMemberPermissions#DISABLED}.
diff --git a/src/main/java/net/dv8tion/jda/internal/interactions/CommandDataImpl.java b/src/main/java/net/dv8tion/jda/internal/interactions/CommandDataImpl.java
index 1b03d07fb0..1538f07e54 100644
--- a/src/main/java/net/dv8tion/jda/internal/interactions/CommandDataImpl.java
+++ b/src/main/java/net/dv8tion/jda/internal/interactions/CommandDataImpl.java
@@ -51,6 +51,7 @@ public class CommandDataImpl implements SlashCommandData
private boolean allowOption = true;
private boolean allowRequired = true;
private boolean guildOnly = false;
+ private boolean nsfw = false;
private DefaultMemberPermissions defaultMemberPermissions = DefaultMemberPermissions.ENABLED;
private final Command.Type type;
@@ -102,6 +103,7 @@ public DataObject toData()
DataObject json = DataObject.empty()
.put("type", type.getId())
.put("name", name)
+ .put("nsfw", nsfw)
.put("options", options)
.put("dm_permission", !guildOnly)
.put("default_member_permissions", defaultMemberPermissions == DefaultMemberPermissions.ENABLED
@@ -135,6 +137,12 @@ public boolean isGuildOnly()
return guildOnly;
}
+ @Override
+ public boolean isNSFW()
+ {
+ return nsfw;
+ }
+
@Nonnull
@Override
public List