Eclipse Discord Bot-发送DM的问题

时间:2018-10-10 16:37:38

标签: javascript eclipse

因此,我在服务器上创建了一个逗趣的bot来娱乐,我试图做的一件事是,如果味精包含我的名字,则向该消息的发送方发送DM。但是,我尝试了各种方法,使用各种命令,但似乎无济于事。我已经在互联网上寻找答案,但是我还没有看到有人使用eclipse来制作机器人,因此他们的代码并不总是对我有用(除非我做错了什么)。有人可以帮我吗?

1 个答案:

答案 0 :(得分:0)

您可以使用一些正则表达式来搜索邮件中出现的姓名。

client.on("message", message => {
  let text = message;
  const containsName = text.search(/name/i); 

  /* search method returns the index of the first letter of the 
     string you're searching for if it is found, else returns -1. 
     Here we are using regex to search for the name, and the 'i' makes 
     it case insensitive.
  */

  if(!(containsName === -1)) message.author.send("whatever you want to DM");
});

您的名称将代替正则表达式中的名称。 有关正则表达式的更多信息,here