【问题标题】:How to make Discord Bot react to a message in a channel, if the message contains a facebook link?如果消息包含 Facebook 链接,如何让 Discord Bot 对频道中的消息做出反应?
【发布时间】:2021-07-13 12:31:45
【问题描述】:

所以我希望在启用广告的特定频道中,当有人粘贴到 facebook、instagram 或任何链接时,机器人会自动使用服务器拥有的特定徽标表情对该消息做出反应。 有没有办法做到这一点?

我正在考虑这样的事情:

client.on('message', message => {
  if (message.channel.id == channel.id.here && message.author.bot == false && message.content("facebook")) { addreactions1(message); }
});

function addreactions1(message) {
  if (message.attachments.size === 1) {
    message.react("facebook.logo.emote")
  return;
}

【问题讨论】:

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


    【解决方案1】:

    由于 .content 返回一个字符串,您可以使用includes() 方法对另一个字符串中的一个字符串执行区分大小写 搜索。例如:

    client.on('message', message => {
      if(message.author.bot) return; //returns doesn't respond to bot or webhook messages.
      if(message.channel.id === "channelid"){
        if(message.content.includes("Facebook"){ //searches for Facebook in the message.
          message.channel.send("Message content had Facebook as a word in it"); // do anything here
        }
      }      
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-07
      • 1970-01-01
      • 1970-01-01
      • 2019-08-12
      • 2019-06-30
      • 2021-05-12
      • 2018-09-07
      • 2021-01-10
      相关资源
      最近更新 更多