Add coinflip slash command
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Bea 2022-11-20 03:07:43 +01:00
parent fb69dcd863
commit b43b882cab
2 changed files with 16 additions and 1 deletions

View File

@ -3,6 +3,7 @@ package wtf.beatrice.hidekobot.listeners;
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter; import net.dv8tion.jda.api.hooks.ListenerAdapter;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import wtf.beatrice.hidekobot.utils.RandomUtil;
public class SlashCommandListener extends ListenerAdapter public class SlashCommandListener extends ListenerAdapter
{ {
@ -13,6 +14,19 @@ public class SlashCommandListener extends ListenerAdapter
if (event.getName().equals("ping")) if (event.getName().equals("ping"))
{ {
event.reply("Pong!").queue(); event.reply("Pong!").queue();
} else if (event.getName().equals("coinflip"))
{
int rand = RandomUtil.getRandomNumber(0, 1);
String msg;
if(rand == 1)
{
msg = ":coin: It's **Heads**!";
} else {
msg = "It's **Tails**! :coin:";
}
event.reply(msg).queue();
} }
} }

View File

@ -17,6 +17,7 @@ public class SlashCommandsUtil
static List<CommandData> allCommands = new ArrayList<>() static List<CommandData> allCommands = new ArrayList<>()
{{ {{
add(Commands.slash("ping", "Test if the bot is responsive.")); add(Commands.slash("ping", "Test if the bot is responsive."));
add(Commands.slash("coinflip", "Flip a coin and get head or tails."));
}}; }};
public static void updateSlashCommands(JDA jdaInstance) public static void updateSlashCommands(JDA jdaInstance)