diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java
index 104398fb..5649f35a 100644
--- a/command/src/main/java/com/jagrosh/jdautilities/command/Command.java
+++ b/command/src/main/java/com/jagrosh/jdautilities/command/Command.java
@@ -15,15 +15,16 @@
*/
package com.jagrosh.jdautilities.command;
-import java.util.Arrays;
-import java.util.Objects;
-import java.util.function.BiConsumer;
-import java.util.function.Predicate;
import net.dv8tion.jda.core.Permission;
import net.dv8tion.jda.core.entities.ChannelType;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.VoiceChannel;
+import java.util.Arrays;
+import java.util.Objects;
+import java.util.function.BiConsumer;
+import java.util.function.Predicate;
+
/**
*
Commands In JDA-Utilities
*
@@ -155,6 +156,12 @@ public abstract class Command
*/
protected boolean hidden = false;
+ /**
+ * {@code true} if this command should reply in dms when terminated.
+ *
Default {@code false}
+ */
+ protected boolean terminateInDms = false;
+
/**
* The {@link com.jagrosh.jdautilities.command.Command.CooldownScope CooldownScope}
* of the command. This defines how far of a scope cooldowns have.
@@ -531,10 +538,25 @@ public boolean isHidden()
return hidden;
}
+ /**
+ * Checks whether or not this command should reply in dms upon termination
+ *
+ * @return {@code true} if the command should reply in dms, otherwise {@code false}
+ */
+ public boolean isTerminatingInDms()
+ {
+ return terminateInDms;
+ }
+
private void terminate(CommandEvent event, String message)
{
if(message!=null)
- event.reply(message);
+ if (terminateInDms) {
+ event.replyInDm(message);
+ } else {
+ event.reply(message);
+ }
+
if(event.getClient().getListener()!=null)
event.getClient().getListener().onTerminatedCommand(event, this);
}
diff --git a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java
index 29b13866..e08eab7e 100644
--- a/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java
+++ b/command/src/main/java/com/jagrosh/jdautilities/command/CommandBuilder.java
@@ -15,8 +15,8 @@
*/
package com.jagrosh.jdautilities.command;
-import com.jagrosh.jdautilities.command.Command.*;
-
+import com.jagrosh.jdautilities.command.Command.Category;
+import com.jagrosh.jdautilities.command.Command.CooldownScope;
import net.dv8tion.jda.core.Permission;
import java.util.Collection;
@@ -56,6 +56,7 @@ public class CommandBuilder
private boolean usesTopicTags = true;
private CooldownScope cooldownScope = CooldownScope.USER;
private boolean hidden = false;
+ private boolean terminateInDms = false;
/**
* Sets the {@link com.jagrosh.jdautilities.command.Command#name name}
@@ -450,6 +451,23 @@ public CommandBuilder setHidden(boolean hidden)
return this;
}
+ /**
+ * Sets the Command built to {@link com.jagrosh.jdautilities.command.Command#terminateInDms when
+ * an error occurs.
+ *
+ *
+ * @param terminateInDms
+ * {@code true} if the Command built is replying in dms upon termination, {@code false} if it will not.
+ *
+ * @return This CommandBuilder
+ */
+
+ public CommandBuilder setTerminatingInDms(boolean terminateInDms)
+ {
+ this.terminateInDms = terminateInDms;
+ return this;
+ }
+
/**
* Builds the {@link com.jagrosh.jdautilities.command.Command Command}
* using the previously provided information.
@@ -492,7 +510,7 @@ public Command build(BiConsumer execution)
guildOnly, requiredRole, ownerCommand, cooldown,
userPermissions, botPermissions, aliases.toArray(new String[aliases.size()]),
children.toArray(new Command[children.size()]), helpBiConsumer, usesTopicTags,
- cooldownScope, hidden)
+ cooldownScope, hidden, terminateInDms)
{
@Override
protected void execute(CommandEvent event)
@@ -509,7 +527,7 @@ private abstract class BlankCommand extends Command
boolean ownerCommand, int cooldown, Permission[] userPermissions,
Permission[] botPermissions, String[] aliases, Command[] children,
BiConsumer helpBiConsumer,
- boolean usesTopicTags, CooldownScope cooldownScope, boolean hidden)
+ boolean usesTopicTags, CooldownScope cooldownScope, boolean hidden, boolean terminateInDms)
{
this.name = name;
this.help = help;
@@ -527,6 +545,7 @@ private abstract class BlankCommand extends Command
this.usesTopicTags = usesTopicTags;
this.cooldownScope = cooldownScope;
this.hidden = hidden;
+ this.terminateInDms = terminateInDms;
}
}
}