简体   繁体   English

如果另一个用户 ping 用户 discord.py,如何让机器人显示用户的信息

[英]How to make a bot display a user's info if another user pings that user discord.py

I am trying to get my bot to display a users info if a user types 'profile?如果用户键入“个人资料”,我试图让我的机器人显示用户信息? [name of other user]'. [其他用户的姓名]'。

if message.content == 'profile?' + user.mention:
   x=display_players_smiles(str(user.mention))            
   y=display_players_frowns(str(user.mention))
   embedVar = discord.Embed(title= str(user.mention), description="This is their profile", color=0x0210ff)
   embedVar.add_field(name="Smiles", value=str(x), inline=False)
   embedVar.add_field(name="Frowns", value=str(y), inline=False)
   await message.channel.send(embed=embedVar)

I tried to use user.mention but it gave me an error.我尝试使用 user.mention 但它给了我一个错误。

If there's no reason for you to use commands Ill give you an example如果你没有理由使用命令我会给你一个例子

@bot.command() # Or `client.command()` - depends how you named your bot instance
async def profile(ctx, user: discord.Member):
    x = display_players_smiles(user.mention)            
    y = display_players_frowns(user.mention)
    embedVar = discord.Embed(title=user.mention, description="This is their profile", color=0x0210ff)
    embedVar.add_field(name="Smiles", value=str(x), inline=False)
    embedVar.add_field(name="Frowns", value=str(y), inline=False)
    await ctx.send(embed=embedVar)

A couple of things worth mentioning:有几点值得一提:

  • You need intents.members enabled您需要启用intents.members
  • At the end of the on_message event you need to addon_message事件结束时,您需要添加
await bot.process_commands(message) # Or `client.process..` - depends how you named it
  • Remember to use commands.Bot , not discord.Client , also remember to use only ONE, not both.记住使用commands.Bot ,而不是discord.Client ,还记得只使用一个,而不是两者。

Take a look at the commands introduction it will hopefully clear up some things for you.看一下命令介绍,它有望为您澄清一些事情。

Here another useful link on how to enable intents & privileged intents, link heer这里是另一个关于如何启用意图和特权意图的有用链接,链接heer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM