想让机器人只向特定的人发送消息

时间:2021-05-13 14:07:49

标签: javascript node.js discord discord.js bots

好的,所以我为我的不和谐机器人做了一个嵌入,但我只希望它向特定的人发送消息。我应该添加什么才能做到这一点?

这是我的代码:

    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),
            );
    }  

})

3 个答案:

答案 0 :(得分:0)

可以查看作者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),
            );
    } 

答案 1 :(得分:0)

或者如果你想要一个以上的人来做

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),
            );
    } 

答案 2 :(得分:0)

试试这个:)

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),
);
}