Reputation:
I need to get all channels that my bot can see into a string array like {#general, #memes}. How do I do this. I have scrolled through the JDA class methods and have found nothing.
Upvotes: 1
Views: 949
Reputation: 351
There are many ways of doing this, and without any code it is quite hard to help you.
First, if you have a JDA
instance you could do
jda.getGuildById("your_guild_id").getChannels();
Second, if you have an event
from a onMessageReceived
event you could do: event.getGuild().getChannels()
@Override
public void onMessageReceived(MessageReceivedEvent event)
{
System.out.println(String.join(",", event.getGuild().getChannels()));
}
Third, if you have an event
from a onReady
event you could do: event.getJDA()getGuildById("your_guild_id").getChannels()
@Override
public void onReady(ReadyEvent event)
{
System.out.println(String.join(",", event.getJDA().getGuildById("your_guild_id").getChannels()));
}
Here is an example:
public class Main implements EventListener{
public static void main(String[] args) {
JDABuilder builder = JDABuilder.createDefault("YOUR_BOT_TOKEN");
builder.addEventListeners(new Main());
builder.build();
}
@Override
public void onReady(ReadyEvent event){
JDA jda = event.getJDA();
Guild guild = jda.getGuildById("YOUR_GUILD_ID");
System.out.println(String.join(",", guild.getChannels());
}
}
Please post some code of what you have if this doesn't help.
Upvotes: 2