首页 > 解决方案 > 有没有办法让 Discord 机器人使用 Discord.py 来回应提及特定用户?

问题描述

我希望我的机器人能够回复对特定用户的提及(例如,一个人提到了我的个人帐户,而机器人回应说我目前不在这里)

有没有办法使用类似的格式来做到这一点?

@client.event
async def on_message(message):

    if message.author == client.user:
        return

    if message.content.startswith('@user_id'):
        await message.channel.send('Im not here leave a message!') 

标签: pythondiscordbotsdiscord.py

解决方案


您需要使用不和谐机器人收到提及的特定格式。格式为 <@!user_id>。

@client.event
async def on_message(message):
    if ("<@!put user id here>" in message.content):
        await message.channel.send("Im not here leave a message!")

如何应用它并为我工作的示例

@client.event
async def on_message(message):
    if ("<@!348256959671173120>" in message.content):
        await message.channel.send("Im not here leave a message!")

推荐阅读