Python 3.x Discord.py向命令添加修改器

Python 3.x Discord.py向命令添加修改器,python-3.x,discord.py,Python 3.x,Discord.py,例如,我见过其他机器人可以执行ban命令!ban 383777390851260426-r你越界了-t 7d-Nodm 我很好奇你是怎么得到修饰符的,比如-r。 感谢您的帮助您的意思是这样吗 @bot.command()#禁止命令 @commands.has_权限(ban_members=True) async def ban(ctx,member:discord.member=None,*,reason=None):#*使reason参数接受所有文本,即使它有空格 如果成员==ctx.mess

例如,我见过其他机器人可以执行ban命令!ban 383777390851260426-r你越界了-t 7d-Nodm

我很好奇你是怎么得到修饰符的,比如-r。 感谢您的帮助

您的意思是这样吗

@bot.command()#禁止命令
@commands.has_权限(ban_members=True)
async def ban(ctx,member:discord.member=None,*,reason=None):#*使reason参数接受所有文本,即使它有空格
如果成员==ctx.message.author:
等待ctx.channel.send(“你不能禁止自己”)
如果成员==无:
等待ctx.channel.send(“你打算禁止谁?”)
如果原因==无:
reason=“未指定原因”
等待成员。禁止(原因=原因)
wait ctx.send(f“{member.notice}因{reason}而被禁止”)

我不知道这是否不是你想要的,也不知道你想要用-t7d等来描述什么,这些被称为参数。通过它们进行解析的一种方法是查看从该方法获得的所有文本,并查找您拥有的每个选项或参数

下面是一个解析在提到成员后得到的参数的示例,请随意修改此代码以将其与其他命令连接(例如将
time\u left
变量解析为Datetime,设置用于取消扫描的计时器,等等)

请注意,这段代码实际上只使用了原因,而不是时间或-nodm,因为这需要更复杂的实现。这只是一个示例,向您展示如何开始这项工作

@command()
async def ban(ctx: Context, member: Member, *args):
    reason_index = args.index("-r")  # Returns -1 if not found, else the position of the "-r"
    reason = args[reason_index+1] if reason_index != -1 else None
    time_index = args.index("-t")
    time_left = args[time_index +1] if time_index != -1 else None
    nodm = True if "-Nodm" in args else False
    await member.ban(reason=reason)
    await ctx.send(f"I banned {member.mention} with reason {reason} for {time_left}")

什么?你能详细说明一下吗?就像你通常能做的那样!禁止@user,但在其他机器人上我看到了你可以做到的!禁止@user,然后使用额外的修饰符,如-r作为理由-t7d等