首页 > 解决方案 > Python Discord.py 任务 TypeError 'method' 对象不可迭代

问题描述

我是法国 Discord bot Developer bot 我的后台任务出错:

@bot.event
async def on_ready():
    print("prêt")


async def ch_pr():
    await bot.wait_until_ready()

    statuses = [
        "0help ou 0?", f"Sur {len(bot.guilds)} serveurs !",
        "Fait en discord.py !", 
        str(len(set(bot.get_all_members))) + "utilisateurs du bot!"
    ]

    while not bot.is_closed():

        status = random.choice(statuses)

        await bot.change_presence(activity=discord.Game(name=status))

        await asyncio.sleep(3)

我的错误是:

File main.py,line 38 in ch_pr:
str(len(set(bot.get_all_members))) + "utilisateurs du bot!"
TypeError: Name 'method' object is not iterable.

感谢帮助。我正在用 repl.it 编码

标签: pythonmethodsdiscorddiscord.pytypeerror

解决方案


它是一个方法,而不是一个属性。您还需要实际调用该方法。

bot.get_all_members()

注意括号()

此外,不要通过垃圾邮件更改您的状态,Discord 不会对此表示赞赏,并且您将获得速率限制。试着每分钟左右做一次。


推荐阅读