0
votes

I'm trying to program a command that mutes every member in the author's voice channel. I'm doing this so myself and my friends can mute ourselves when we swap to in-game voice chat automatically. But for reasons I cannot explain, I can never get it to work. Here's my code:

@commands.command()
@commands.has_permissions(mute_members=True)
async def mute(self, ctx):
    if ctx.author.voice and ctx.author.voice.channel:
        channel = ctx.author.voice.channel
        for member in channel.members:
            await member.edit(mute=True)
    else:
        await ctx.send("You are not connected to a voice channel!")

This is the full error

I understand that the bot and the author need a mute members permission, but both of them do! I even made sure that they were at the top of the role list, and I edited the voice channel permissions to allow mute members for the author and bot. No matter what I do, I always keep getting the same error! Any help would be greatly appreciated!

1
I wonder it might be something about the bots having the general permission to mute a member in the server but not in that specific category?chluebi
I did give permissions for both the bot and the author to mute members on the server, voice channel, and the category the voice channel is in.LukeBenVader1
Do you have any checks on your command(s)? MissingPermissions is a CheckFailure.Patrick Haugh
Oh crap I do. My bad, I thought I included it in the code above. I changed it.LukeBenVader1
You might try using has_guild_permissions instead. I suspect the channel permissions don't have mute_members because you can't mute people in a text channel. You would have to check channel.permissions_for(ctx.author) in the body of your callback.Patrick Haugh

1 Answers

0
votes
async def has_channel_permissions(**kwargs):
    def predicate(ctx):
        if ctx.author.voice is not None:
            if ctx.author.voice.channel is not None:
                if kwargs in dict(ctx.author.voice.channel.permissions_for(ctx.author)) and kwargs in dict(commands.user:
                    return True
                else:
                    return False
        await ctx.send("You are not connected to a voice channel!")
        return False
    return commands.check(predicate)


@commands.command()
@has_channel_permissions(mute_members=True)
async def mute(self, ctx):
    channel = ctx.author.voice.channel
    for member in channel.members:
        await member.edit(mute=True)