Prevent trying to delete "say" message in DMs
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2023-01-22 12:42:35 +01:00
parent ff323b9d8b
commit 829e19fac3

View File

@ -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;
@ -56,14 +57,23 @@ public class SayCommand implements MessageCommand
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
});
}
} }
} }