Print friends-list to console Discord.py

China☆狼群 提交于 2019-12-02 10:17:22

discord.ClientUser is a class. You want the ClientUser instance that represents your bots user account. You can get this with bot.user, as commands.Bot is a subclass of Client

@bot.command()
async def userlist(ctx):
    for user in bot.user.friends:
        print (user.name+"#"+user.discriminator)

From what the error states, discord.ClientUser.friends does not seem to have "unpackable" data.

For example,
"abcdefg" would iterate as "a", "b", "c", etc.
[1, 2, 3, 4] would iterate as 1, 2, 3, 4
The value stored in discord.ClientUser.friends appears to be an object and cannot be iterated.

Try doing print discord.ClientUser.friends to confirm this.

discord.ClientUser.friends is not iterable - thus you can't run through its items in a for loop. I don't know that package, but try to see what type it is (you can do this like this - print(type(discord.ClientUser.friends))) and then see how to access the data in it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!