0
votes

I have a mute command in my bot but i want to add a timer on it, not really sure how to tho, this is my current code. It adds the code correctly and it all sends correctly but the duration i'm not really sure about. Any help would be appreciated!

Edit: I got the duration working, but how would i convert it into minutes/hours etc.?

@client.command()
@commands.has_permissions(manage_messages=True)
async def mute(ctx, member: discord.Member, mute_time : int, *, reason=None):
    role = discord.utils.get(ctx.guild.roles, name="[Muted]")
    await member.add_roles(role)
    await ctx.send(f'**Muted** {member.mention}\n**Reason: **{reason}\n**Duration:** {mute_time}')

    embed = discord.Embed(color=discord.Color.green())
    embed.add_field(name=f"You've been **Muted** in {ctx.guild.name}.", value=f"**Action By: **{ctx.author.mention}\n**Reason: **{reason}\n**Duration:** {mute_time}")
    await member.send(embed=embed)

    await asyncio.sleep(mute_time)
    await member.remove_roles(role)
    await ctx.send(f"**Unmuted {member.mention}**")
1

1 Answers

0
votes

I use your code in minimal example and it's work well. What problems do you have? Example:

@client.command()
@commands.has_permissions(manage_messages=True)
async def mute(ctx, mute_time : int):
    await ctx.send("Muted")
    await asyncio.sleep(mute_time)
    await ctx.send("Unmuted")

Exactly one minute passed. Result:

Result