试着让一个角色出现在一个列表中,但是变得很奇怪

2024-04-27 03:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我试图使用的代码片段(我已经在代码开头定义了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@角色时,会出现以下错误:

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

Tags: inclientmessagehomeliblocallinemsg
1条回答
网友
1楼 · 发布于 2024-04-27 03:27:17

由于@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)

相关问题 更多 >