python - 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 编码
解决方案
它是一个方法,而不是一个属性。您还需要实际调用该方法。
bot.get_all_members()
注意括号()
。
此外,不要通过垃圾邮件更改您的状态,Discord 不会对此表示赞赏,并且您将获得速率限制。试着每分钟左右做一次。
推荐阅读
- django - TypeError:“NoneType”对象在 Django 单元测试中不可为消息下标
- r - 根据 checkboxGroupInput 的多个图
- mongodb - Mongo $geoNear 不在所有记录中搜索
- tensorflow - TensorFlow tfrecord 编辑(读取然后写入文件)OutOfRange 错误
- ios - 如何使用子视图控制器中的按钮单击更改 tabBar 项目标题
- wordpress - 如何在自动播放时取消静音 wordpress fvplayer 视频
- javascript - 如何使用javascript合并两个对象?
- android - 带有 React Native 的 Google 地图面板
- android - 无法从 LinkedIn 应用程序获取访问令牌。它在 onActivityResult 返回 null
- svg - 将 chart.js 绘制为 svg