【问题标题】:Want to make bot only send messages to a specific person想让机器人只向特定的人发送消息
【发布时间】:2021-08-03 19:45:27
【问题描述】:
好的,所以我为我的 discord 机器人做了一个嵌入,但我只希望它向特定的人发送消息。我应该添加什么才能做到这一点?
这是我的代码:
if ( msg.content === "WhoseMyWaifu"){
const embed = new Discord.MessageEmbed()
msg.reply(
embed.setImage('https://toppng.com/public/uploads/thumbnail/load-68-more-imagesgrid-view-me-dio-11563057753kl6hlthvsz.png'),
embed.setColor('RANDOM'),
embed.setFooter(msg.author.username),
);
}
})
【问题讨论】:
标签:
javascript
node.js
discord
discord.js
bots
【解决方案1】:
你可以查看作者的ID
if (msg.content === "WhoseMyWaifu" && msg.author.id === "SOME_USER_ID"){
const embed = new Discord.MessageEmbed()
msg.reply(
embed.setImage('https://toppng.com/public/uploads/thumbnail/load-68-more-imagesgrid-view-me-dio-11563057753kl6hlthvsz.png'),
embed.setColor('RANDOM'),
embed.setFooter(msg.author.username),
);
}
【解决方案2】:
或者如果你想让不止一个人来做
const user = ["id1","id2",....]
if (msg.content === "WhoseMyWaifu" && user.includes(message.author.id)){
const embed = new Discord.MessageEmbed()
msg.reply(
embed.setImage('https://toppng.com/public/uploads/thumbnail/load-68-more-imagesgrid-view-me-dio-11563057753kl6hlthvsz.png'),
embed.setColor('RANDOM'),
embed.setFooter(msg.author.username),
);
}
【解决方案3】:
试试这个:)
const users = ["user1", "user2"] // add anyones ID her
if (msg.content == "WhoseMyWaifu" || users.includes(msg.author.id)) {
let embed = new Discord.MessageEmbed
msg.reply(
embed.setImage('https://toppng.com/public/uploads/thumbnail/load-68-more-imagesgrid-view-me-dio-11563057753kl6hlthvsz.png'),
embed.setColor('RANDOM'),
embed.setFooter(msg.author.username),
);
}