Java 如何在创建通道后获取其id

Java 如何在创建通道后获取其id,java,discord,discord-jda,Java,Discord,Discord Jda,我正在创建一个生成临时通道的bot,我有一个问题,在直接创建通道并将其分配给变量后,如何获取通道的id 这是我的代码: public void onGuildVoiceJoin(GuildVoiceJoinEvent event) { if(event.getChannelJoined().getIdLong() == 703255821508673546L) { event.getGuild().getCategoryById("7044181

我正在创建一个生成临时通道的bot,我有一个问题,在直接创建通道并将其分配给变量后,如何获取通道的id

这是我的代码:

public void onGuildVoiceJoin(GuildVoiceJoinEvent event) {

            if(event.getChannelJoined().getIdLong() == 703255821508673546L) {
            event.getGuild().getCategoryById("704418165710651492").createVoiceChannel("%s".format("channel" + event.getMember().getEffectiveName())).addPermissionOverride(event.getMember().getGuild().getPublicRole(), null, EnumSet.of(Permission.VOICE_CONNECT, Permission.VIEW_CHANNEL)).addMemberPermissionOverride(event.getMember().getIdLong(), EnumSet.of(Permission.MANAGE_CHANNEL, Permission.VOICE_CONNECT, Permission.MANAGE_PERMISSIONS, Permission.VOICE_MOVE_OTHERS), null).queue();
            event.getGuild().getCategoryById("704418165710651492").createTextChannel("%s".format("channel" + event.getMember().getEffectiveName())).queue();
        }
    }
由于
queue()
是一个异步操作,因此必须使用回调函数

category.createVoiceChannel(名称)
.addPermissionOverride(角色、allowRole、DenRole)
.addPermissionOverride(成员、allowMember、denyMember)
.队列(频道->{
System.out.println(“语音频道的ID:+channel.getId());
});

请参阅和。

您可以使用以下分类方法浏览创建的频道列表:

    /**
 * All {@link net.dv8tion.jda.api.entities.TextChannel TextChannels}
 * listed for this Category
 *
 * @return Immutable list of all child TextChannels
 */
@Nonnull
List<TextChannel> getTextChannels();

/**
 * All {@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannels}
 * listed for this Category
 *
 * @return Immutable list of all child VoiceChannels
 */
@Nonnull
List<VoiceChannel> getVoiceChannels();
/**
*所有{@link net.dv8tion.jda.api.entities.TextChannel TextChannels}
*已列为此类别
*
*@return所有子文本通道的不可变列表
*/
@非空
列出getTextChannel();
/**
*所有{@link net.dv8tion.jda.api.entities.VoiceChannel VoiceChannel}
*已列为此类别
*
*@return所有子语音频道的不可变列表
*/
@非空
列出getVoiceChannel();


尽管如前所述,您不能保证这些通道已经创建,因为队列是一种异步方法。

请在代码中使用变量。