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