How would I go about printing to console a list of all my friends? I'm hoping to be able to achieve this with the Discord.py library, hopefully someone here knows.
I currently get the error:
for user in discord.ClientUser.friends: TypeError: 'property' object is not iterable
Program:
token = ""
prefix = "::"
import discord
import asyncio
import codecs
import sys
import io
from discord.ext import commands
from discord.ext.commands import Bot
print ("waiting")
bot = commands.Bot(command_prefix=prefix, self_bot=True)
bot.remove_command("help")
@bot.event
async def on_ready():
print ("Friends")
@bot.command()
async def userlist(ctx):
for user in discord.ClientUser.friends:
print (user.name+"#"+user.discriminator)
bot.run(token, bot=False)
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.discord.ClientUser
is a class. You want theClientUser
instance that represents your bots user account. You can get this withbot.user
, ascommands.Bot
is a subclass ofClient
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, 4The value stored in
discord.ClientUser.friends
appears to be an object and cannot be iterated.Try doing
print discord.ClientUser.friends
to confirm this.