Python 我不能在命令中使用append

Python 我不能在命令中使用append,python,discord,discord.py,Python,Discord,Discord.py,我是python新手,我想做一个简单的机器人 我想从用户那里获取姓名,并将其添加到列表中 但是我不能在@bot.commad中使用列表方法 我的代码: @bot.command(pass_context=True) async def add(ctx,*args): tempP = [*args] for el in tempP: players.append(tempP[el]) await ctx.send('{} players: {}'.forma

我是python新手,我想做一个简单的机器人 我想从用户那里获取姓名,并将其添加到列表中 但是我不能在@bot.commad中使用列表方法

我的代码:

@bot.command(pass_context=True)
async def add(ctx,*args):
    tempP = [*args]
    for el in tempP:
        players.append(tempP[el])
    await ctx.send('{} players: {}'.format(len(players), ', '.join(players)))
和回溯:

Traceback (most recent call last):
  File "C:\Python37\lib\site-packages\discord\ext\commands\core.py", line 83, in wrapped
    ret = await coro(*args, **kwargs)
  File "c:\Users\MREZ\poll\bot.py", line 17, in add
    players.add(tempP[el])
AttributeError: 'Command' object has no attribute 'add'

ps:我可以使用
players=[*args]
byt,因为我从players列表中丢失了以前的元素。

尝试使用append而不是add,因为我假设这是一个列表。 第17行:


错误消息显示的代码与您向我们显示的代码不同。确保保存了.py文件,重新启动Python和bot并重试。我想说我同时使用了'add'和'append',但没有起作用“我可以使用players=[*args]byt,因为我从players列表中丢失了以前的元素。”错误消息清楚地告诉您,
players
在代码达到这一点时不是列表。这可能是因为它在代码中的其他地方被替换为
命令
,而您没有显示给我们。这类事情是避免使用全局变量的警告之一。
players.append(tempP[el])