i want to make tempmute command in discord.py, but I don't have idea how can I do this. So I'm asking SO.
I want to make command which will add Muted
role to user for specified time, e.g. mute @member 10m spamming
-> it'll mute user for 10 minutes with reason = "spamming". (My trails are over time expressed only in secconds). I want to can chose time between s (seccond), m (minute), h (hour), d (day).
This is what I made:
@client.command()
@commands.has_permissions(kick_members=True)
async def tempmute(ctx, member: discord.Member, time=0, reason=None):
if reason == None:
reason = "no reason provided"
if member.id == ctx.author.id:
await ctx.send(f"{ctx.author.mention}, you can't mute yourself")
role = discord.utils.get(ctx.guild.roles, name="Muted")
if role in ctx.guild.roles:
await member.add_roles(role)
await ctx.send(f"Muted {member.mention}")
await asyncio.sleep(time)
await member.remove_roles(role)
else:
await ctx.send("No role named `Muted`!")