【问题标题】:discord.py rewrite tempmute commanddiscord.py 重写 tempmute 命令
【发布时间】:2020-10-19 19:35:29
【问题描述】:

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

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

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

【问题讨论】:

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


    【解决方案1】:

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

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

    一分钟过去了。结果:

    【讨论】:

    • 哦,我刚刚检查了一下,我没有导入异步,我以为我做到了,哈哈,我将如何将秒转换为分钟和小时等?
    • 您可以使用几分钟:mute_time * 60 和几小时:mute_time * 3600。在asyncio.sleep 第一个参数延迟总是秒。 Block for delay seconds.
    猜你喜欢
    • 2021-02-09
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 2021-07-15
    • 2020-05-03
    • 2020-11-06
    • 2021-03-30
    • 2020-09-11
    相关资源
    最近更新 更多