首页 > 解决方案 > discord.py 重写 tempmute 命令

问题描述

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

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

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

标签: discorddiscord.pydiscord.py-rewrite

解决方案


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

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

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

结果


推荐阅读