【问题标题】:Trying make a role be in a list but getting weird error尝试使角色出现在列表中但出现奇怪的错误
【发布时间】:2018-07-10 04:25:22
【问题描述】:

这是我正在尝试使用的代码的 sn-p(我已经在代码开头定义了 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

【问题讨论】:

  • 您不能将rgb 既作为列表名称又作为函数名称。

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


【解决方案1】:

感谢@jasonharper 命令名称与列表冲突

固定代码:

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

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 2021-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-27
    • 2019-12-15
    • 2023-01-13
    相关资源
    最近更新 更多