我想要一个命令
/profile (可选)(可选2)
/profile ->会给出我自己的简介
/profile personA ->将给出personA的简介
/profile 2019年->将在2019年给出我自己的简介
/profile personA 2019 ->将在2019年给出personA的简介
目前,我只做了第一个,我需要帮助添加可选参数。
async def profile(self, ctx):
print("profile")发布于 2021-09-23 16:29:57
对可选参数使用typing.Optional。未传递的值将为None。
/profile ->这两个参数都是空的。
/profile personA ->成员将为personA,年份为无
/profile 2019年->成员将为零,年份为2019年
/profile personA 2019 ->成员将为personA,年份为2019年
然后,您可以检查成员是否为None,以及是否将ctx.author分配给成员。
from typing import Optional
async def profile(self, ctx, member: Optional[discord.Member], year: Optional[int]):
if member is None:
member = ctx.author
...至于如何显示概要文件,它取决于您存储数据的方式,并且在这里可能过于宽泛/偏离主题。
https://stackoverflow.com/questions/69300066
复制相似问题