Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Interaction Localization support #78

Merged
merged 10 commits into from
Oct 16, 2022
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
import net.dv8tion.jda.api.interactions.DiscordLocale;
import net.dv8tion.jda.api.interactions.commands.DefaultMemberPermissions;
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
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.SlashCommandData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
import net.dv8tion.jda.api.interactions.commands.build.SubcommandGroupData;
import net.dv8tion.jda.api.interactions.commands.build.*;

import java.util.ArrayList;
import java.util.HashMap;
Expand Down Expand Up @@ -72,6 +68,11 @@
*/
public abstract class SlashCommand extends Command
{

Chew marked this conversation as resolved.
Show resolved Hide resolved
protected Map<DiscordLocale, String> nameLocalization = new HashMap<>();

OurTwinkie marked this conversation as resolved.
Show resolved Hide resolved
protected Map<DiscordLocale, String> descriptionLocalization = new HashMap<>();

/**
* This option is deprecated in favor of using Discord's permissions<br>
* This deprecation can be ignored if you intend to support normal and slash commands.
Expand Down Expand Up @@ -383,6 +384,17 @@ public CommandData buildCommandData()
{
data.addOptions(getOptions());
}

//Add localization
if (!getNameLocalization().isEmpty())
{
data.setNameLocalizations(getNameLocalization());
}
if (!getDescriptionLocalization().isEmpty())
{
data.setDescriptionLocalizations(getDescriptionLocalization());
}

// Check for children
if (children.length != 0)
{
Expand Down Expand Up @@ -505,4 +517,12 @@ else if(cooldownScope.equals(CooldownScope.GUILD) && event.getGuild()==null)
else
return front+" "+cooldownScope.errorSpecification+"!";
}

OurTwinkie marked this conversation as resolved.
Show resolved Hide resolved
public Map<DiscordLocale, String> getNameLocalization() {
return nameLocalization;
}

OurTwinkie marked this conversation as resolved.
Show resolved Hide resolved
public Map<DiscordLocale, String> getDescriptionLocalization() {
return descriptionLocalization;
}
}