在某人获得某个角色后,如何让一个不和谐的 js bot 在 dm 中发送消息

时间:2021-05-28 17:27:54

标签: javascript node.js npm discord bots

我的代码:

const Discord = require('discord.js');
const client = new Discord.Client(); 
const prefix = '$';

client.once('ready' , () => {
    console.log('M-am trezit din morti!');
});

client.on('message' , message  =>{
   if(!message.content.startsWith(prefix) || message.author.bot) return;

   const args = message.content.slice(prefix.length).split(/ +/);
   const command= args.shift().toLowerCase();

   if(command === 'about'){
       
   }else if(command === 'troll'){
       const messages = ["Esti un ratat!!", "Akatsuki este cel mai tare!", "Lui Tobi ii plac baietii!", "Invata sa joci, noobule!" , "Esti pe langa cu jocul!", "Cum naiba ai ajuns in factiunea asta?"]

       const randomMessage = messages[Math.floor(Math.random() * messages.length)];
    
       message.channel.send(randomMessage)
   }
});

client.login('notgonnashowit');

1 个答案:

答案 0 :(得分:0)

你可以这样使用:

    client.on("guildMemberUpdate", (oldMember, newMember) => {
      // when Member is updated check if the Member has a role by ID
      if (newMember._roles.includes("ROLE ID HERE")){
          // then DM them
          newMember.send('message to dm');
        } 
    });

要使用上述内容,您必须在机器人仪表板中打开服务器成员意图:

Like this