Discord Py Command userinfo 不工作,它说信息不在列表中
Discordpy Comand userinfo isn't working, it says that the information is not in list
我有这个命令可以在我的 discord 机器人中显示用户信息
@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)
但是显示错误:
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
谁能解释一下这是怎么回事?
我设法修复了它,用户信息代码是完美的,但是在代码的顶部我写了这个:
#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)
但是应该这样才能正常工作
#NECESAROS
intents = discord.Intents.default()
intents.members = True
startup = time.time()
#PREFIJO COMANDO
client = commands.Bot(command_prefix = '!', intents=intents, help_command=None)
这解决了我的问题,它发生是因为我试图启用斜线命令「有了这部分 intents=discord.Intents.default()」并且需要它似乎使它破坏了我的 userinfo 命令
长这样
我有这个命令可以在我的 discord 机器人中显示用户信息
@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)
但是显示错误:
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
谁能解释一下这是怎么回事?
我设法修复了它,用户信息代码是完美的,但是在代码的顶部我写了这个:
#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)
但是应该这样才能正常工作
#NECESAROS
intents = discord.Intents.default()
intents.members = True
startup = time.time()
#PREFIJO COMANDO
client = commands.Bot(command_prefix = '!', intents=intents, help_command=None)
这解决了我的问题,它发生是因为我试图启用斜线命令「有了这部分 intents=discord.Intents.default()」并且需要它似乎使它破坏了我的 userinfo 命令
长这样