Skip to content

Instantly share code, notes, and snippets.

@jagrosh
Last active November 12, 2024 03:50
Show Gist options
  • Save jagrosh/5ab3dddd1a318f523066a667ea88e55d to your computer and use it in GitHub Desktop.
Save jagrosh/5ab3dddd1a318f523066a667ea88e55d to your computer and use it in GitHub Desktop.
get a list of user ids from a server
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.jagrosh.idgrabber;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import javax.security.auth.login.LoginException;
import net.dv8tion.jda.core.AccountType;
import net.dv8tion.jda.core.JDABuilder;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Guild;
import net.dv8tion.jda.core.events.message.MessageReceivedEvent;
import net.dv8tion.jda.core.exceptions.RateLimitedException;
import net.dv8tion.jda.core.hooks.ListenerAdapter;
/**
*
* @author John Grosh ([email protected])
*/
public class IDGrabber extends ListenerAdapter {
public static void main(String[] args) throws IOException, LoginException, IllegalArgumentException, RateLimitedException {
new JDABuilder(AccountType.CLIENT).setToken(Files.readAllLines(Paths.get("config.txt")).get(0)).addListener(new IDGrabber()).buildAsync();
}
@Override
public void onMessageReceived(MessageReceivedEvent event) {
if(event.getAuthor().equals(event.getJDA().getSelfUser()) && event.getMessage().getContent().startsWith("self.ids"))
{
String id = event.getMessage().getContent().substring(8).trim();
Guild guild = event.getJDA().getGuildById(id);
if(guild==null)
event.getChannel().sendMessage("No guild with id `"+id+"`").queue();
else
{
StringBuilder builder = new StringBuilder(guild.getName()+" ("+guild.getId()+")\r\n---");
guild.getMembers().forEach(m -> builder.append("\r\n").append(m.getUser().getId()).append(" ").append(m.getUser().getName()).append("#").append(m.getUser().getDiscriminator()));
try {
Files.write(Paths.get("guild-ids-"+guild.getId()+".txt"), builder.toString().getBytes());
event.getChannel().sendFile(new File("guild-ids-"+guild.getId()+".txt"), new MessageBuilder().append("All user IDs from "+guild.getName()+":").build()).queue();
} catch (IOException ex) {
event.getChannel().sendMessage("Failed to save+upload file").queue();
}
}
}
}
}
@tenkgyattohiorizz
Copy link

.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment