discord-jda / JDA

Java wrapper for the popular chat & VOIP service: Discord https://discord.com
Apache License 2.0
4.26k stars 730 forks source link

Bot can't delete voice channel even with MANAGE_CHANNEL #2678

Closed mfawcett closed 3 months ago

mfawcett commented 3 months ago

General Troubleshooting

Version of JDA

5.0.0-beta.23

Expected Behaviour

Delete the voice channel

Code Example for Reproduction Steps

Category category = guild.createCategory("test")
    .addRolePermissionOverride(guild.getPublicRole().getIdLong(), null, EnumSet.of(Permission.VIEW_CHANNEL))
    .addRolePermissionOverride(guild.getBotRole().getIdLong(), EnumSet.of(Permission.VIEW_CHANNEL, Permission.MANAGE_CHANNEL), null)
    .complete();

VoiceChannel vc = guild
    .createVoiceChannel("hello", category)
    .setBitrate(guild.getMaxBitrate())
    .complete();

vc.delete().complete();

Code for JDABuilder or DefaultShardManagerBuilder used

builder
            .enableIntents(GatewayIntent.GUILD_MEMBERS, GatewayIntent.MESSAGE_CONTENT)
            .setMemberCachePolicy(MemberCachePolicy.ALL)
            .setEventManagerProvider(id -> eventManager)
            .setBulkDeleteSplittingEnabled(false)
            .setActivity(Activity.playing("Picking Teams"))
            .disableCache(CacheFlag.ACTIVITY, CacheFlag.MEMBER_OVERRIDES, CacheFlag.VOICE_STATE);

        // Disable member chunking on startup
        builder.setChunkingFilter(ChunkingFilter.NONE);

        // Disable presence updates and typing events
        builder.disableIntents(GatewayIntent.GUILD_PRESENCES, GatewayIntent.GUILD_MESSAGE_TYPING);

        // Consider guilds with more than 50 members as "large".
        // Large guilds will only provide online members in their setup and thus reduce bandwidth if chunking is disabled.
        builder.setLargeThreshold(50);

Exception or Error

[ForkJoinPool.commonPool-worker-1] ERROR RestAction - Encountered error while processing success consumer
net.dv8tion.jda.api.exceptions.InsufficientPermissionException: Cannot perform action due to a lack of Permission. Missing permission: MANAGE_CHANNEL
    at net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin.checkPermission(GuildChannelMixin.java:64)
    at net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin.checkPermission(GuildChannelMixin.java:56)
    at net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin.checkCanManage(GuildChannelMixin.java:71)
    at net.dv8tion.jda.internal.entities.channel.mixin.middleman.GuildChannelMixin.delete(GuildChannelMixin.java:43)
MinnDevelopment commented 3 months ago

Does your bot have the VOICE_CONNECT permission in this channel? It is a required permission to have access to the channel in the first place.

mfawcett commented 3 months ago

Confirmed that adding VOICE_CONNECT fixes the issue.