Discordpy Comand userinfo isn’t working, it says that the information is not in list

I have this command to show userinfo in my discord bot

@client.command()
async def userinfo(ctx, *, user: discord.Member = None):
    if isinstance(ctx.channel, discord.DMChannel):
       return
    if user is None:
        user = ctx.author      
    date_format = "%a, %d %b %Y %I:%M %p"
    embed = discord.Embed(color=0xdfa3ff, description=user.mention)
    embed.set_author(name=str(user), icon_url=user.avatar_url)
    embed.set_thumbnail(url=user.avatar_url)
    embed.add_field(name="Unido", value=user.joined_at.strftime(date_format))
    members = sorted(ctx.guild.members, key=lambda m: m.joined_at)
    embed.add_field(name="Posicion de Servidor", value=str(members.index(user)+1))
    embed.add_field(name="Registrado", value=user.created_at.strftime(date_format))
    if len(user.roles) > 1:
        role_string = ' '.join([r.mention for r in user.roles][1:])
        embed.add_field(name="Roles [{}]".format(len(user.roles)-1), value=role_string, inline=False)
    perm_string = ', '.join([str(p[0]).replace("_", " ").title() for p in user.guild_permissions if p[1]])
    embed.add_field(name="Permisos de Administracion", value=perm_string, inline=False)
    embed.set_footer(text='ID: ' + str(user.id))
    return await ctx.send(embed=embed)

But it shows an error:

File “main.py”, line 280, in userinfo
embed.add_field(name=”Posicion de Servidor”, value=str(members.index(user)+1)) ValueError: <Member
id=568157479020527636 name=’ElmerKao’ discriminator=’0058′ bot=False
nick=None guild=> is not in list

Anyone can explain what is happening?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I manage to repair it, the userinfo code was perfect, but at the top of the code I had this writen:

#NECESAROS
intents = discord.Intents.default()
intents.members = True
startup = time.time()

#PREFIJO COMANDO
client = commands.Bot(command_prefix = '!', intents=discord.Intents.default(), help_command=None)

But it should be like this in order to make it work poperly

#NECESAROS
intents = discord.Intents.default()
intents.members = True
startup = time.time()

#PREFIJO COMANDO
client = commands.Bot(command_prefix = '!', intents=intents, help_command=None)

This fixed my problem, it happend because I was trying to enable slash commands「With this part intents=discord.Intents.default()」and that was needed it seems that making that broke my userinfo command

This is how it looks like
Discordpy Comand userinfo isn't working, it says that the information is not in list


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x