如何检查是否提到了某个用户 [英] How to check if a certain user was mentioned
本文介绍了如何检查是否提到了某个用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试检查消息中是否提到了某个用户(@user).这是我目前拥有的:
I am trying to check if a user has been mentioned (@user) in a message. This is what i currently have:
} if (message.content.includes('<@796406791323516999>')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected')
}
(包裹在客户端中,用于检测发送消息的时间)
(This is wrapped in a client.on detecting when a message is sent)
我在这里做错什么了?
推荐答案
您可以使用 Mentions#members#has
使用成员的ID来检查是否有提及,以及该成员是否为一个提及.
You can use Mentions#members#has
using the member's id to check if there were any mentions, and if the member was one of the mentions.
const mentions = message.mentions.members;
if (!mentions) return message.channel.send('No Mentions Error Message.');
if (mentions.has('796406791323516999')) {
message.channel.bulkDelete(1);
message.channel.send('User mention was detected');
}
这篇关于如何检查是否提到了某个用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文