Prevent trying to delete "say" message in DMs
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ff323b9d8b
commit
829e19fac3
@ -1,6 +1,7 @@
|
|||||||
package wtf.beatrice.hidekobot.commands.message;
|
package wtf.beatrice.hidekobot.commands.message;
|
||||||
|
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
|
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
@ -53,17 +54,26 @@ public class SayCommand implements MessageCommand
|
|||||||
{
|
{
|
||||||
|
|
||||||
String messageContent;
|
String messageContent;
|
||||||
if(args.length != 0 && !args[0].isEmpty())
|
if (args.length != 0 && !args[0].isEmpty())
|
||||||
{
|
{
|
||||||
messageContent = args[0];
|
messageContent = args[0];
|
||||||
} else {
|
} else
|
||||||
|
{
|
||||||
event.getMessage().reply("\uD83D\uDE20 Hey, you have to tell me what to say!")
|
event.getMessage().reply("\uD83D\uDE20 Hey, you have to tell me what to say!")
|
||||||
.queue();
|
.queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getChannel().sendMessage(messageContent).queue();
|
event.getChannel().sendMessage(messageContent).queue();
|
||||||
event.getMessage().delete().queue();
|
|
||||||
|
|
||||||
|
if (event.getChannel() instanceof TextChannel)
|
||||||
|
{
|
||||||
|
event.getMessage().delete().queue(response -> {
|
||||||
|
// nothing to do with the response
|
||||||
|
}, error -> {
|
||||||
|
// ignore the error if we couldn't delete it, we were probably missing permissions
|
||||||
|
// without this block it would print a stack trace in console
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user