Skip to content

Commit ffbc5b5

Browse files
committed
add support for user-installable commands
1 parent 820630d commit ffbc5b5

File tree

3 files changed

+21
-3
lines changed

3 files changed

+21
-3
lines changed

build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ version = "1.0.0"
88

99
repositories {
1010
mavenCentral()
11+
maven { url = uri("https://jitpack.io") }
1112
}
1213

1314
dependencies {
14-
implementation("net.dv8tion:JDA:5.0.0-beta.2")
15-
implementation("ch.qos.logback:logback-classic:1.2.10")
15+
// implementation("net.dv8tion:JDA:5.1.2")
16+
implementation("io.github.JDA-Fork:JDA:55d824408c")
17+
implementation("ch.qos.logback:logback-classic:1.4.12")
1618

1719
implementation("com.google.code.gson:gson:2.8.9")
1820

src/main/java/us/ajg0702/bots/ajsupport/CommandListener.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ public void onSlashCommandInteraction(SlashCommandInteractionEvent e) {
111111
return;
112112
}
113113

114+
115+
114116
guild.updateCommands()
115117
.addCommands(Commands.slash("remove", "Unregister commands (aj only)"))
116118
.addCommands(Commands.slash("stop", "Stop the bot (aj only)"))
119+
.and(bot.getJDA().updateCommands()) // removes global commands
117120
.submit().thenRun(() -> hook.sendMessage("Removed the commands!").setEphemeral(true).queue());
118121

119122

src/main/java/us/ajg0702/bots/ajsupport/SupportBot.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import net.dv8tion.jda.api.entities.User;
1212
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
1313
import net.dv8tion.jda.api.exceptions.InvalidTokenException;
14+
import net.dv8tion.jda.api.interactions.IntegrationType;
15+
import net.dv8tion.jda.api.interactions.InteractionContextType;
1416
import net.dv8tion.jda.api.interactions.commands.OptionType;
1517
import net.dv8tion.jda.api.interactions.commands.build.Commands;
1618
import net.dv8tion.jda.api.requests.GatewayIntent;
@@ -92,7 +94,18 @@ private SupportBot(JDA jda) throws InterruptedException {
9294
getLogger().debug("Adding command "+name);
9395

9496
// commands.addCommands(Commands.slash(name, cutString(value, 100)));
95-
globalCommands.addCommands(Commands.slash(name, cutString(value, 100)));
97+
globalCommands.addCommands(
98+
Commands.slash(name, cutString(value, 100))
99+
.setContexts(
100+
InteractionContextType.BOT_DM,
101+
InteractionContextType.PRIVATE_CHANNEL,
102+
InteractionContextType.GUILD
103+
)
104+
.setIntegrationTypes(
105+
IntegrationType.GUILD_INSTALL,
106+
IntegrationType.USER_INSTALL
107+
)
108+
);
96109
//guild.upsertCommand(name, value.substring(0, Math.min(99, value.length()))).queue();
97110
});
98111
commands.addCommands(

0 commit comments

Comments
 (0)