尝试使角色出现在列表中,但出现奇怪的错误

时间:2018-07-10 04:25:23

标签: python python-3.x discord discord.py

这是我要开始工作的代码片段(我已经在代码开头定义了rgb[]

    @client.command(pass_context=True,description="Linusifies a role")
   client.command(pass_context=True,description="Linusifies a role")
@has_permissions(administrator = True)
async def rgb(ctx, role : discord.Role):
    if role in rgb:
        msg = "{}'s rgb is turned off :disappointed_relieved:"
        rgb.remove(role)
        await client.send_message(ctx.message.channel, msg)
    else:
        msg = "{}'s rgb has been turned on :christmas_tree:".format(role)
        rgb.append(role)
    await client.send_message(ctx.message.channel, msg)

这是我尝试在服务器上执行#rgb @role时出现的错误:

Traceback (most recent call last):
  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 50, in wrapped
    ret = yield from coro(*args, **kwargs)
  File "<stdin>", line 4, in rgb
TypeError: argument of type 'Command' is not iterable

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/bot.py", line 846, in process_commands
    yield from command.invoke(ctx)
  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 374, in invoke
    yield from injected(*ctx.args, **ctx.kwargs)
  File "/home/python/.local/lib/python3.6/site-packages/discord/ext/commands/core.py", line 54, in wrapped
    raise CommandInvokeError(e) from e
discord.ext.commands.errors.CommandInvokeError: Command raised an exception: TypeError: argument of type 'Command' is not iterable

1 个答案:

答案 0 :(得分:0)

由于@jasonharper,命令名称与列表冲突

固定代码:

p178153953