Home>

I am writing a bot in python and I want to implement the mutecommand for it, I saw options with adding a role to the user, but they do not work (I put the role without rights even higher than the admin and could write to the chat anyway). Also made this code:

@bot.command(pass_context=True, aliases=['mute', 'mute'])
@commands.has_permissions(administrator=True)
async def mut(ctx, member: discord.Member= None, amout: str= None, *, reason= None):
    await member.edit(mute= True)
    now= datetime.now()
    emb= discord.Embed()
    hour= now. hour
    minute= now.minute
    second= now second
    emb.set_author(name=member, icon_url=member.avatar_url)
    emb.add_field(name='MUT', value=f'{hour}:{minute}:{second}')
    emb.set_footer(text=f'Made by admin {ctx.author.name}', icon_url=ctx.author.avatar_url)
    await ctx.send(embed=emb)

But it just turns off MICROPHONEon behalf of the server, and I need you to also not be able to write, not just speak...

  • Answer # 1

    when creating a muted role, you need in each category (NOT A CHANNEL, BUT CATEGORIES IN WHICH CHANNELS) to prohibit this role from what you want to block for muted ones.

    I personally use this code:

    @client.command()
    @commands.has_any_role(here is admin/moder role id)
    async def mut(ctx, user: discord.Member, time: int,*, reason):
        role= user.guild.get_role(id of the mute role) # id of the role that the user will receive
        emb= discord.Embed( title= '✅Succeeded', description=f"User {user} was muted!\nTime spent in mut: {time} minutes\nReason for muting: {reason}!", color= discord.Color .green())
        emb.set_footer(text= 'Action performed by moderator/admin -' + ctx.author.name, icon_url= ctx.author.avatar_url)
        await ctx.send( embed= emb)
        await user.add_roles(role) #mute role
        await asyncio.sleep(time * 60) #waits the required number of seconds multiplied by 60
        await user.remove_roles(role) #remove the mute role
    

    it gives the role of a mute for a certain number of minutes

    but if you want your own code, then I added it (also for issuing a role)

    @bot.command(pass_context=True, aliases=['mute', 'mute'])
    @commands.has_permissions(administrator=True)
    async def mut(ctx, member: discord.Member= None, time: int, *, reason= None):
        role= user.guild.get_role(id of the mute role) # id of the role that the user will receive
        emb= discord.Embed()
        emb.set_author(name=member, icon_url=member.avatar_url)
        emb.set_footer(text=f'Made by admin {ctx.author.name}', icon_url=ctx.author.avatar_url)
        await ctx.send(embed=emb)
        await asyncio.sleep(time * 60) #waits the required number of seconds multiplied by 60
        await user.remove_roles(role) #remove the mute role
    

    Sorry, I removed the datetime part.

    Oh, and if you are bored, you can get a list of all channels (voice and text) and forbid what you need for voice channels for text. But roughly speaking, in return for issuing a role with the same rights, you complicate the work and forbid the user to do something without issuing a role.

  • Answer # 2

    when creating a muted role, you need in each category (NOT A CHANNEL, BUT CATEGORIES IN WHICH CHANNELS) to prohibit this role from what you want to block for muted ones.

    I personally use this code:

    @client.command()
    @commands.has_any_role(here is admin/moder role id)
    async def mut(ctx, user: discord.Member, time: int,*, reason):
        role= user.guild.get_role(id of the mute role) # id of the role that the user will receive
        emb= discord.Embed( title= '✅Succeeded', description=f"User {user} was muted!\nTime spent in mut: {time} minutes\nReason for muting: {reason}!", color= discord.Color .green())
        emb.set_footer(text= 'Action performed by moderator/admin -' + ctx.author.name, icon_url= ctx.author.avatar_url)
        await ctx.send( embed= emb)
        await user.add_roles(role) #mute role
        await asyncio.sleep(time * 60) #waits the required number of seconds multiplied by 60
        await user.remove_roles(role) #remove the mute role
    

    it gives the role of a mute for a certain number of minutes

    but if you want your own code, then I added it (also for issuing a role)

    @bot.command(pass_context=True, aliases=['mute', 'mute'])
    @commands.has_permissions(administrator=True)
    async def mut(ctx, member: discord.Member= None, time: int, *, reason= None):
        role= user.guild.get_role(id of the mute role) # id of the role that the user will receive
        emb= discord.Embed()
        emb.set_author(name=member, icon_url=member.avatar_url)
        emb.set_footer(text=f'Made by admin {ctx.author.name}', icon_url=ctx.author.avatar_url)
        await ctx.send(embed=emb)
        await asyncio.sleep(time * 60) #waits the required number of seconds multiplied by 60
        await user.remove_roles(role) #remove the mute role
    

    Sorry, I removed the datetime part.

    Oh, and if you are bored, you can get a list of all channels (voice and text) and forbid what you need for voice channels for text. But roughly speaking, in return for issuing a role with the same rights, you complicate the work and forbid the user to do something without issuing a role.