discord.py 重写 tempmute 命令

discord.py rewrite tempmute command

我的机器人中有一个静音命令,但我想在上面添加一个计时器,但不太确定该怎么做,这是我当前的代码。它正确地添加了代码,并且都正确发送了,但我不太确定持续时间。如有任何帮助,我们将不胜感激!

编辑:我得到了持续时间,但我如何将它转换成 minutes/hours 等?

@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}**")

我在最小示例中使用了您的代码,它运行良好。你有什么问题?示例:

@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")

整整一分钟过去了。结果: