mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-02 22:47:41 +01:00
Add DiscordService#getMemberById
This commit is contained in:
parent
a7f4d6b16b
commit
376abc4aab
@ -4,6 +4,8 @@ import net.essentialsx.api.v2.events.discord.DiscordChatMessageEvent;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
/**
|
||||
* A class which provides numerous methods to interact with EssentialsX Discord.
|
||||
*/
|
||||
@ -47,6 +49,13 @@ public interface DiscordService {
|
||||
*/
|
||||
InteractionController getInteractionController();
|
||||
|
||||
/**
|
||||
* Gets an {@link InteractionMember} by their Discord ID.
|
||||
* @param id The ID of the member to look up.
|
||||
* @return A future which will complete with the member or null if none is reachable.
|
||||
*/
|
||||
CompletableFuture<InteractionMember> getMemberById(final String id);
|
||||
|
||||
/**
|
||||
* Gets unstable API that is subject to change at any time.
|
||||
* @return {@link Unsafe the unsafe} instance.
|
||||
|
@ -26,9 +26,11 @@ import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
|
||||
import net.essentialsx.api.v2.services.discord.DiscordService;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionController;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionException;
|
||||
import net.essentialsx.api.v2.services.discord.InteractionMember;
|
||||
import net.essentialsx.api.v2.services.discord.MessageType;
|
||||
import net.essentialsx.api.v2.services.discord.Unsafe;
|
||||
import net.essentialsx.discord.interactions.InteractionControllerImpl;
|
||||
import net.essentialsx.discord.interactions.InteractionMemberImpl;
|
||||
import net.essentialsx.discord.interactions.commands.ExecuteCommand;
|
||||
import net.essentialsx.discord.interactions.commands.ListCommand;
|
||||
import net.essentialsx.discord.interactions.commands.MessageCommand;
|
||||
@ -466,6 +468,19 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<InteractionMember> getMemberById(final String id) {
|
||||
final CompletableFuture<InteractionMember> future = new CompletableFuture<>();
|
||||
getGuild().retrieveMemberById(id).queue(member -> {
|
||||
if (member != null) {
|
||||
future.complete(new InteractionMemberImpl(member));
|
||||
return;
|
||||
}
|
||||
future.complete(null);
|
||||
}, fail -> future.complete(null));
|
||||
return future;
|
||||
}
|
||||
|
||||
public JDA getJda() {
|
||||
return jda;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user