python - 有没有办法让 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!')
解决方案
您需要使用不和谐机器人收到提及的特定格式。格式为 <@!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!")
推荐阅读
- java - java 是否像 python 和 C#mvc 一样提供 html/jsp 扩展方法?
- algorithm - 两个和问题 - 有两个数组和突变
- svelte - 为使用 isActive 路由精确路径?
- vue.js - 带有操作按钮列的 v-data-table 中的重复单击事件
- r - 如何访问R中for循环中的excel文件列?
- java - Cannot resolve method 'parse' in 'DockerImageName' when using Testcontainers and gradle in JUnit5
- c++ - 如何在此 OpenMP 求和示例中删除依赖项
- android - 等待设备时出错:AVD Pixel_2_API_30 的模拟器进程被杀死
- amazon-web-services - 无法在 Ubuntu 上安装 Galera Manger
- r - 编织到pdf时如何阻止rmarkdown生成“附加包”