如何使我的python discord bot检测到命令中提到的某个用户?

时间:2020-09-13 19:32:11

标签: python discord bots discord.py

我正在尝试获取一条命令,以使其具有异常,在该异常中,当对bot本身执行ping操作时,将发送另一条消息,而不是普通的普通消息。而且我似乎找不到在discord.py中对我有利的某个命令,有什么建议吗?

@bot.command()
async def fight(ctx):
    if (insert the scanned mention == 'insert discord bot ping'):
        await ctx.send('message')
        await ctx.send('another message')```

1 个答案:

答案 0 :(得分:1)

您可以使用ctx.message.mentions获取所有提到的用户的列表。如果您拥有该人的Member / User实例,则可以执行member.mentioned_in(message),或者在您的情况下:

if client.user.mentioned_in(message):
    # do something here

如果没有Member实例,则可以遍历ctx.message.mentions,然后检查每个实例,以查看它们是否是您需要检查的实例。

id = 12345678910  # The Discord id of the member you want to check
for user in ctx.message.mentions:
    if user.id == id:
        # do something here