[英]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:有几点值得一提:
intents.members
enabledintents.members
on_message
event you need to addon_message
事件结束时,您需要添加await bot.process_commands(message) # Or `client.process..` - depends how you named it
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.