mirror of
https://github.com/EssentialsX/Essentials.git
synced 2024-12-22 09:08:01 +01:00
Add support for role arguments in slash commands
This commit is contained in:
parent
2a1957229f
commit
ba5a8becfc
@ -4,22 +4,10 @@ package net.essentialsx.api.v2.services.discord;
|
||||
* Represents an argument type to be shown on the Discord client.
|
||||
*/
|
||||
public enum InteractionCommandArgumentType {
|
||||
STRING(3),
|
||||
INTEGER(4),
|
||||
BOOLEAN(5),
|
||||
USER(6),
|
||||
CHANNEL(7);
|
||||
|
||||
private final int id;
|
||||
InteractionCommandArgumentType(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the internal Discord ID for this argument type.
|
||||
* @return the internal Discord ID.
|
||||
*/
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
STRING,
|
||||
INTEGER,
|
||||
BOOLEAN,
|
||||
USER,
|
||||
CHANNEL,
|
||||
ROLE,
|
||||
}
|
||||
|
@ -51,6 +51,13 @@ public interface InteractionEvent {
|
||||
*/
|
||||
InteractionChannel getChannelArgument(String key);
|
||||
|
||||
/**
|
||||
* Helper method to get the role representation of the argument by the given key or null if none by that key is present.
|
||||
* @param key The key of the argument to lookup.
|
||||
* @return the role value or null
|
||||
*/
|
||||
InteractionRole getRoleArgument(String key);
|
||||
|
||||
/**
|
||||
* Gets the channel ID where this interaction occurred.
|
||||
* @return the channel ID.
|
||||
|
@ -9,6 +9,7 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionChannel;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionEvent;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionRole;
|
||||
import net.essentialsx.discord.EssentialsDiscord;
|
||||
import net.essentialsx.discord.util.DiscordUtil;
|
||||
|
||||
@ -79,6 +80,12 @@ public class InteractionEventImpl implements InteractionEvent {
|
||||
return mapping == null ? null : new InteractionChannelImpl(mapping.getAsGuildChannel());
|
||||
}
|
||||
|
||||
@Override
|
||||
public InteractionRole getRoleArgument(String key) {
|
||||
final OptionMapping mapping = event.getOption(key);
|
||||
return mapping == null ? null : new InteractionRoleImpl(mapping.getAsRole());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getChannelId() {
|
||||
return event.getChannel().getId();
|
||||
|
Loading…
Reference in New Issue
Block a user