Actually register the command as user app context

This commit is contained in:
2024-08-05 22:16:32 +02:00
parent 7c626f2dac
commit cc24b59bec
3 changed files with 20 additions and 13 deletions
+9 -2
View File
@@ -69,11 +69,18 @@
</resources>
</build>
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.dv8tion</groupId>
<groupId>com.github.freya022</groupId>
<artifactId>JDA</artifactId>
<version>5.0.1</version>
<version>feature~user-installable-apps-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>club.minnced</groupId>
@@ -3,10 +3,11 @@ package me.youhavetrouble.noted;
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.JDABuilder;
import net.dv8tion.jda.api.entities.Activity;
import net.dv8tion.jda.api.interactions.IntegrationType;
import net.dv8tion.jda.api.interactions.InteractionContextType;
import net.dv8tion.jda.api.interactions.commands.OptionType;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
import net.dv8tion.jda.api.requests.restaction.CommandListUpdateAction;
import java.io.*;
import java.util.Collections;
@@ -21,8 +22,6 @@ public class Main {
public static void main(String[] args) throws InterruptedException {
loadProperties();
jda = JDABuilder.createLight(properties.getProperty("DISCORD_TOKEN"), Collections.emptyList())
.setCallbackPool(Executors.newVirtualThreadPerTaskExecutor())
.setActivity(Activity.customStatus("Notekeeping..."))
@@ -31,15 +30,16 @@ public class Main {
jda.awaitReady();
CommandListUpdateAction commands = jda.updateCommands();
commands = commands.addCommands(
Commands.slash("note", "Get a note")
jda.upsertCommand(Commands.slash("note", "Get a note")
.setIntegrationTypes(IntegrationType.GUILD_INSTALL, IntegrationType.USER_INSTALL)
.addOptions(
new OptionData(OptionType.STRING, "note-id", "The ID of the note").setRequired(true),
new OptionData(OptionType.BOOLEAN, "ephermeal", "Whether the note should be ephermal").setRequired(false)
)
);
commands.queue();
.setContexts(InteractionContextType.BOT_DM, InteractionContextType.GUILD, InteractionContextType.PRIVATE_CHANNEL)
)
.queue();
}
private static void loadProperties() {
@@ -12,16 +12,16 @@ public class SlashCommandListener extends ListenerAdapter {
public void onSlashCommandInteraction(SlashCommandInteractionEvent event) {
switch (event.getName()) {
case "note" -> {
OptionMapping noteIdOption = event.getOption("content");
OptionMapping noteIdOption = event.getOption("note-id");
OptionMapping ephemeralOption = event.getOption("ephemeral");
if (noteIdOption == null) {
event.reply("Please provide a note ID.").setEphemeral(true).queue();
return;
}
Note note = new Note(
"Note Title",
"Sample Note Title",
null,
"Test Note content",
"Bottom text",
null,
null,
null,