Why is my tempmute command muting people for 1 second when I tell it 10 seconds?

Viewed 63

My mute command is muting people for 1 second instead of 10 seconds, and i don't know why. Does anyone see something wrong in the code?

@client.command()
@commands.has_guild_permissions(kick_members=True)
async def mute(ctx, member: discord.Member, time, reason=None):
    muted_role = discord.utils.get(ctx.guild.roles, name="Muted")
    time_convert = {"s":1, "m":60, "h":3600,"d":86400}
    tempmute = int(time[0]) * time_convert[time[-1]]
    await member.add_roles(muted_role)
    await ctx.send(f'{member} has been muted for {time}. Reason: {reason}.', delete_after=5)
    await asyncio.sleep(tempmute)
    await member.remove_roles(muted_role)
1 Answers

It looks like the mistake is in the following line:

tempmute = int(time[0]) * time_convert[time[-1]]

Instead try the following:

tempmute = int(time[:-1]) * time_convert[time[-1]]

The full code would be:

@client.command()
@commands.has_guild_permissions(kick_members=True)
async def mute(ctx, member: discord.Member, time, reason=None):
    muted_role = discord.utils.get(ctx.guild.roles, name="Muted")
    time_convert = {"s":1, "m":60, "h":3600,"d":86400}
    tempmute = int(time[:-1]) * time_convert[time[-1]]
    await member.add_roles(muted_role)
    await ctx.send(f'{member} has been muted for {time}. Reason: {reason}.', delete_after=5)
    await asyncio.sleep(tempmute)
    await member.remove_roles(muted_role)

time[0] is 1 and time[-1] is m etc.

Related