![](/img/trans.png)
[英]Is there is a way to add role to someone who has mentioned in a message in discord.js?
[英]Is there is a way to DM someone that is mentioned in a message with discord.js?
有没有办法向 discord.js 消息中提到的人发送消息?
这是我的代码。
client.on("message", message => {
if (message.author.bot) {return}
let person = message.content.mentions
person.send("My message")
})
由于某种原因它不起作用
mentions
不是content
的有效属性。 您正在寻找Message.mentions
,它是MessageMentions
object。
client.on("message", message => {
if (message.author.bot) return false;
// Getting the first mentioned user in the message.
const person = message.mentions.users.first();
// Checking if any user was mentioned.
if (!person) return message.reply("Please mention someone.");
person.send("Hello!").then(() => {
message.reply(`Message sent to ${person.tag}`);
}).catch(error => {
message.reply(`Couldn't send the message to ${person.tag}. | ${error}`);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.