所以我正在创建一个用户信息命令,当我运行该命令时,它不起作用并且没有出现错误。
这是我的代码:
@commands.command()
async def info(self, ctx, *, member: discord.Member):
embed=discord.Embed(color=0xFFFFF0, title=f"{ctx.author.name}'s Info", description="Displays user information.")
embed.set_thumbnail(url=f"{ctx.author.avatar_url}")
embed.add_field(name="User ID:", value=f"{ctx.author.id}", inline=True)
embed.add_field(name="Color:", value=f"{ctx.author.top_role.mention}\n[{ctx.author.top_role.colour}]")
embed.add_field(name="Join Date:", value=f"{ctx.author.joined_at}")
embed.timestamp = datetime.datetime.utcnow()
embed.set_footer(text=f"Requested by: {ctx.author}", icon_url=ctx.author.avatar_url)
await ctx.send(embed=embed)
答案 0 :(得分:0)
你基本上把ctx.author
,作者是你,如果你这样做,你就不能显示其他用户的信息。如果您想显示其他用户的信息,您应该使用 if
语句。
最后一件事是Joindate。它会发送这个奇怪的时间 04:22:23.699000
。因此,您应该将时间转换为 strftime
。
更新后的代码:
@commands.command()
async def info(self, ctx, *, member: discord.Member = None): #changed the member to None so it will work if the user didnt mention the member
if member == None: # shows that if the use didnt mention the member (if statement)
member = ctx.author
# changed all embed of the ctx.author to member
embed=discord.Embed(title=f"{member.name}'s Info", description="Displays user information.", color=0xFFFFF0)
embed.set_thumbnail(url=f"{member.avatar_url}")
embed.add_field(name="User ID:", value=f"{member.id}", inline=True)
embed.add_field(name="Color:", value=f"{member.top_role.mention}\n[{member.top_role.colour}]")
embed.add_field(name="Join Date:", value= member.joined_at.strftime("%B %d %Y\n%H:%M:%S %p")) # make the time look nice
embed.timestamp = datetime.datetime.utcnow()
embed.set_footer(text=f"Requested by: {ctx.author}", icon_url=ctx.author.avatar_url) # changed member to ctx.author als
await ctx.send(embed=embed)