To modify an entity in JDA you usually have to use the manager. You can acquire an instance of a manager through getManager()
on almost every entity.
TextChannel channel = guild.getTextChannelById(573629024102776853L);
channel.getManager()
.setName("Total Users:" + guild.getMemberCache().size())
.queue(); // this is needed, otherwise the request won't be made to discord
If the id for the channel is incorrect it will throw an NPE on channel.getManager()
because getTextChannelById
will return null.
I used getMemberCache()
instead of getMembers()
because its more efficient for this kind of code. The size is directly available on the cache-view instance and does not require copying the entire cache into a list which is effectively what getMembers()
does.
0
solved How can I update the voice channel when a user enters the guild with JDA