Answers for "how to make a tempmute command discord.py"

0

tempmute discord.py

@client.command()
async def tempmute(ctx, member: discord.Member, time: int, d, *, reason=None):
    guild = ctx.guild

    for role in guild.roles:
        if role.name == "Muted":
            await member.add_roles(role)

            embed = discord.Embed(title="muted!", description=f"{member.mention} has been tempmuted ", colour=discord.Colour.light_gray())
            embed.add_field(name="reason:", value=reason, inline=False)
            embed.add_field(name="time left for the mute:", value=f"{time}{d}", inline=False)
            await ctx.send(embed=embed)

            if d == "s":
                await asyncio.sleep(time)

            if d == "m":
                await asyncio.sleep(time*60)

            if d == "h":
                await asyncio.sleep(time*60*60)

            if d == "d":
                await asyncio.sleep(time*60*60*24)

            await member.remove_roles(role)

            embed = discord.Embed(title="unmute (temp) ", description=f"unmuted -{member.mention} ", colour=discord.Colour.light_gray())
            await ctx.send(embed=embed)

            return
Posted by: Guest on December-22-2020
0

temp mute command discord.py

@bot.command()
async def tempmute(ctx, member: discord.Member, time: int, d, *, reason=None):
    guild = ctx.guild
    mutedRole = discord.utils.get(guild.roles, name="Muted")
    if not mutedRole:
        mutedRole = await guild.create_role(name="Muted")

    for channel in guild.channels:
        await channel.set_permissions(mutedRole, speak=False, send_messages=False, read_message_history=True)

    await member.add_roles(mutedRole)

    embed = discord.Embed(title="TempMuted!", description=f"{member.mention} has been tempmuted.", colour=discord.Colour.light_gray())
    embed.add_field(name="Reason:", value=reason, inline=False)
    embed.add_field(name="Time for the mute:", value=f"{time}{d}", inline=False)
    await ctx.send(embed=embed)

    if d == "s":
        mutetime = time

    if d == "m":
        mutetime = time*60

    if d == "h":
        mutetime = time*60*60

    if d == "d":
        mutetime = time*60*60*24

    with open("TXT_FILE_PATH", "w+") as mutetimef:
        mutetime.write(mutetime)
    
    while True:
        with open("TXT_FILE_PATH", "w+") as mutetimef:
            if int(mutetimef.read()) == 0:
                await member.remove_roles(mutedRole)

                embed = discord.Embed(title="Unmute (temp mute expired) ", description=f"Unmuted -{member.mention} ", colour=discord.Colour.light_gray())
                await ctx.send(embed=embed)
  
                return
            else:
                mutetime -= 1
                mutetimef.seek(0)
                mutetimef.truncate()
                mutetimef.write(mutetime)
        await asyncio.sleep(1)
Posted by: Guest on July-20-2021

Code answers related to "how to make a tempmute command discord.py"

Python Answers by Framework

Browse Popular Code Answers by Language