启动discord.py机器人时出现错误

时间:2020-08-30 12:19:52

标签: python discord.py

@bot.command()
@commands.has_role('new role')
async def role(ctx, member: discord.Member=None,role_time : int, role: discord.Role = None):
    if not member:
        await ctx.send("Who do you want me to give a role?")
        return
    role = discord.utils.get(ctx.guild.roles, name="muted")
    await member.add_roles(role)
    await ctx.send("Ok, I did it :thumpsup:")
    if role is None:
       return await self.bot.say('Pls write a role')

    await asyncio.sleep(role_time)
    await member.remove_roles(role)
    await ctx.send("The time of the role of {} is up".format(member))

这确实使我为此:

async def role(role_time : int, role: discord.Role = None, ctx, member: discord.Member=None,):<br/>
                   ^
SyntaxError: non-default argument follows default argument

(^位于ctx上

1 个答案:

答案 0 :(得分:2)

非默认参数必须位于默认参数之前。将函数定义更改为:

async def role(ctx, role_time : int, member: discord.Member=None, role: discord.Role = None):

您还必须相应地修改函数调用。