我正在尝试创建一个命令,其中有一个机器人PM,前面提到的用户遵循预先键入的消息前缀。我该怎么做?
答案 0 :(得分:0)
确保您拥有最新版本的node和discord.js。在discord.js的最新更新中添加了使用提及
bot.on('message', message => {
if (message.content.startsWith(prefix + "pm")) {
for (let user of message.mentions.users.values()) {
if (message.content.includes("a couple letters")) {
user.send("pre-recorded message");
} else if (message.content.includes("different letters")) {
user.send(" a different pre-recorded message");
}
}
}
});
答案 1 :(得分:0)
对于迟到的回复感到抱歉。在我的评论中要求澄清之后睡着了。只需创建一个对象即可将密钥(字母)映射到消息中。
let messageObject = {
ab: "This is a message that sent from the keyword ab.",
vd: "This is another message that sent from the keyword vd",
test: "And a third diff message that sent from the keyword test"
};
client.on("message", message => {
if(message.content.toLowerCase().startsWith("!dm")) {
let args = message.content.split(" ").slice(1);
let user = message.guild.member(args[0].replace(/[<@!>]/g,"")).user;
let keyword= args[1];
if(keyword in messageObject){
return user.send(messageObject[keyword]);
}
return message.channel.send("That is not a valid keyword!");
}
});