How do I add slash commands just for one user in JDA? Like commands just accessible in…
- User
How do I add slash commands just for one user in JDA? Like commands just accessible in the dms?
- Assistant
To add slash commands that are accessible only in direct messages (DMs) for one user in JDA, you can use the following code example:
import net.dv8tion.jda.api.JDABuilder; import net.dv8tion.jda.api.entities.ApplicationCommand; import net.dv8tion.jda.api.entities.ApplicationCommandOption; import net.dv8tion.jda.api.events.*; import net.dv8tion.jda.api.hooks.ListenerAdapter; import javax.security.auth.login.LoginException; import java.util.List; public class SlashCommandExample extends ListenerAdapter { public static void main(String[] args) throws LoginException { // Replace DISCORD_TOKEN with your bot's token JDABuilder.createDefault("DISCORD_TOKEN") .addEventListeners(new SlashCommandExample()) .build(); } @Override public void onReady(ReadyEvent event) { // Get the user's DM channel event.getJDA().getUserById("USER_ID").openPrivateChannel().queue(channel -> { // Create the slash command List<ApplicationCommandOption> options = List.of( ApplicationCommandOption.create("param", "Description of the parameter", 1, 1) ); ApplicationCommand command = ApplicationCommand.create("command_name", "Description of the command", options); // Register the command in the user's DM channel channel.upsertCommand(command).queue(); }); } // Add other event handlers based on your application's requirements }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.