Print users to console excluding those with default avatars Discord.py
Clash Royale CLAN TAG#URR8PPP
Print users to console excluding those with default avatars Discord.py
How would I go about printing to console a list of users in my server, excluding those who have the default/null avatar? My current code looks like this, but does not work. It print's the list of users, but it does not exclude those with default avatar. This is using the Discord.py rewrite.
#!/usr/bin/python
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 ("users with avatars")
@bot.command(pass_context=True)
async def userlist(ctx):
for user in list(ctx.message.guild.members):
if user.avatar == None:
pass
else:
for user in list(ctx.message.guild.members):
print (user.name+"#"+user.discriminator)
bot.run(token, bot=False)
2 Answers
2
User
s also have a User.default_avatar
attribute. If you compare that to User.avatar
, you should be able to filter out the users for which those match.
User
User.default_avatar
User.avatar
@bot.command()
async def userlist(ctx):
for user in ctx.guild.members:
if user.avater != user.default_avater:
print (user.name+"#"+user.discriminator)
This is assuming that your real problem isn't that you're looping through all the members again inside the else
. Try this variation of your solution:
else
@bot.command()
async def userlist(ctx):
for user in ctx.guild.members:
if user.avatar:
print (user.name+"#"+user.discriminator)
Maybe user.avatar
does not return None
when user's avatar is blank.
Try to find a value that user.avatar
returns when user's avatar is blank.
user.avatar
None
user.avatar
for user in list(ctx.message.gild.members):
print(user.name + " = " + user.avatar)
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.