M
M
Max2022-01-17 23:18:35
Python
Max, 2022-01-17 23:18:35

Understand understand why the mut command does not work?

Here is the code

#временный мут
@bot.command(pass_context = True)
@commands.has_any_role('mute' , 908382396112592926 ) #Вводите название вашей роли и её ID
async def mute(ctx, member: discord.Member = None, time: int = None, reason = None ):
    muted_role = discord.utils.get( ctx.message.guild.roles, name = mute )
    if member is None:
        await ctx.send(embed = discord.Embed(description = f'{ ctx.author.name }, **обязательно укажите (@Rall пример) пользователя!**', color = 5574e0 ))
        await ctx.message.add_reaction( '❌' )
    else:
        if time is None:
            await ctx.send(embed = discord.Embed(description = f'{ ctx.author.name }, **обязательно укажите время (минуты)!**', color = 5574e0 ))
            await ctx.message.add_reaction( '❌' )
        else:
            if muted_role is None:
                await ctx.send(embed = discord.Embed(description = f'{ ctx.author.name }, **обязательно создайте роль mute!**', color = 5574e0 ))
                await ctx.message.add_reaction( '❌' )
            else:
                await member.add_roles(muted_role, reason = reason, atomic = True)
                await ctx.message.add_reaction( '✅' )
                await asyncio.sleep(time * 60)
                await member.remove_roles(muted_role)


Although the role is mute created

Here is the error:
discord.ext.commands.errors.MissingAnyRole: You are missing at least one of the required roles: 'mute'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-17
@NeZuSS

How to understand? Turn on your head and read the documentation.

@commands.has_any_role('mute' , 908382396112592926 )

Reading the docs :
A check() that is added that checks if the member invoking the command has any of the roles specified . This means that if they have one out of the three roles specified, then this check will return True.

"If the caller of the command has any of the specified roles." Those. this command can only be used by a member who has either a role called 'mute' or a role with id 908382396112592926.
Next, look at the underlying stupidity.
muted_role = discord.utils.get( ctx.message.guild.roles, name = mute )

You passed the mute function as name. Does this even make sense to you? Maybe he meant name = 'mute'? But then it means that only a muted user can call the command. I doubt that you wanted it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question