问题描述
我尝试在线研究,但没有其他问题可以帮助我解决我的问题.
i've tried to research online, but no other questions were able to help me with my issue.
这是我的场景.
我正在 discord.py 中发出静音命令.
i am making a mute command in discord.py.
我希望时间是可选的,但如果没有指定时间,我希望该参数成为原因的一部分.
i want the time to be optional, but if the time is not specified i want that argument to be part of the reason.
澄清我的意思:
@client.command() @commands.has_permissions(kick_members=true) async def mute(ctx, member: member = none, time: int = none, *, reason = none): pass
这里,如果 time 为 none,则使其成为 reason 的一部分.
here, if time is none, then make it part of reason.
机器人将接受这两个:
!mute @user 1h 垃圾邮件和!mute @user spam
这可能吗?
推荐答案
您可以选择异步等待,然后将用户取消静音:
you can optionally wait asynchronously and then unmute the user:
@bot.command() async def mute(ctx, member: discord.member, time: typing.optional[int]): await member.edit(mute=true) if time: await asyncio.sleep(time) await member.edit(mute=false)