本文介紹了如何在 discord.py 中設(shè)置可選參數(shù)?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我嘗試在線研究,但沒有其他問題可以幫助我解決我的問題.
I've tried to research online, but no other questions were able to help me with my issue.
這是我的場景.
我正在 discord.py 中發(fā)出靜音命令.
I am making a mute command in discord.py.
我希望時間是可選的,但如果沒有指定時間,我希望該參數(shù)成為原因的一部分.
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)
這篇關(guān)于如何在 discord.py 中設(shè)置可選參數(shù)?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!