discord.py重写tempmute命令

时间:2020-06-29 15:29:45

标签: discord discord.py discord.py-rewrite

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

编辑:我得到了持续时间,但是如何将其转换为分钟/小时等?

@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 个答案:

答案 0 :(得分:0)

我在最小的示例中使用您的代码,并且效果很好。你有什么问题?示例:

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

恰好一分钟过去了。结果:

Result