Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 不断获得;缺少1个必需的位置参数“;但这一论点已经给出_Python_Discord_Discord.py - Fatal编程技术网

Python 不断获得;缺少1个必需的位置参数“;但这一论点已经给出

Python 不断获得;缺少1个必需的位置参数“;但这一论点已经给出,python,discord,discord.py,Python,Discord,Discord.py,我的discord机器人有问题。(discord.py) 这是我的密码: @bot.command() async def mute(ctx): muteRole = discord.Guild.get_role(845612659940524032) if(message.author.kick_members == True): return else: await ctx.send('You don\'t have the perm

我的discord机器人有问题。(discord.py)

这是我的密码:

@bot.command()
async def mute(ctx):
    muteRole = discord.Guild.get_role(845612659940524032)
    if(message.author.kick_members == True):
        return

    else:
        await ctx.send('You don\'t have the permission for that')
我觉得一切都很好。但当我测试命令时,总是会出现以下错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: get_role() missing 1 required positional argument: 'role_id'

有人能帮我吗?

我想你还不太明白这是怎么回事
discord.Guild
是一个类,不是一个实例,您正在调用它的函数
get\u role()
。这就是你的错误的来源。要解决此问题,请改用实例
ctx.guild

muteRole = ctx.guild.get_role(845612659940524032)
另外,
message.author.kick\u成员在这里不起作用。首先,因为
message
没有在任何地方定义,所以请改用
ctx.message
。此外,
ctx.message.author
没有属性
kick_members
,可以尝试改用decorator

@bot.command()
@has_permissions(kick_members=True)
async def mute(ctx):
    muteRole = ctx.guild.get_role(845612659940524032)

我猜您正在尝试使用非静态的类帮会方法,您传递给
get_role
的数字被解释为
self
参数,这将解释您的异常。你不应该从职业公会实例化吗?谢谢你的快速回答!但是当我尝试你的代码时,我只得到另一个错误代码:NameError:name'has_permissions'未定义抱歉,我的问题我不太习惯于这种重写…然后你需要从discord.ext.commands导入
。导入有_权限,MissingPermissions
nvm忘记保存..它可以工作。谢谢