'JDA Check if channel exists

Hello is there any option to check if the channel already exists? I have already tried sooooo many things but I can't code this I get errors or the code doesn't work and I didn't get any error in the console.



Solution 1:[1]

var guild = jda.getGuildById(serverId);
var channels = guild.getChannels();

You may get the channel list by this way.

Solution 2:[2]

If you want to check by name:

JDA jda = jdaBuilder.build();
jda.awaitReady();

//Put the ID of your guild here
long guildID = 1L;

//check if the name of this channel exists
String channelName = "do I exist?";

//Ignoring case, whether the channel is found to already exist
boolean channelFound = false;

List<GuildChannel> channels = jda.getGuildById(guildID).getChannels();
for(GuildChannel channel : channels) {
    if(channel.getName().equalsIgnoreCase(channelName)) {
        channelFound = true;
        break;
    }
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Luminous
Solution 2