不和谐js。机器人不回复消息

时间:2020-12-27 20:34:14

标签: discord discord.js bots

client.on("message", message =>{
  if(message.channeltype = 'dm')
    if (message.content === "confess")
      message.channel.send("OOOOOOoooooo A SECRET??!?!?! WHAT IS IT?!??!") 
      message.channel.awaitMessages("response", message =>{
      C = message.content
      message.reply("Um.... theres two servers that this bot works on. 1: Loves in the snow or 2:?Moomins and Shep's Therapy Service?. Pick a number to send it to one of them")
      client.on("message", message => { //////// SWITCH THIS LINE OUT FOR THE THING THAT WAITS FOR NEW MESSAGES
      if (message.content === "2")
        WDI = message.author
        WDID = message.author.id
        message.channel.get(WDIC2).send("Ok ok so who did it is" + WDI + "and their id is" + WDID)
        message.channel.get(CC2).send(C)
    
      if (message.content === "1")
        WDI = message.author
        WDID = message.author.id
        message.channel.get(WDIC1).send("Ok ok so who did it is" + WDI + "and their id is" + WDID)
        message.channel.get(CC1).send(C)
        
    })
        
      })})   

为什么我的机器人不回复我的消息? 我先承认然后它会说这个消息,但它没有检测到我继续并回复了。我该怎么办?

1 个答案:

答案 0 :(得分:1)

请阅读文档。我想说 Discord.JS 文档是一个非常方便的参考。

对于第一部分,message.channeltype 不是真正的属性,并且不要使用 =。那是为了设置变量,使用 ===== 代替(What is the difference?)。您可以使用 message.channel.type,也可以使用 instanceof,如下所示:message.channel instanceof Discord.DMChannel。将 Discord 替换为您调用的任何 Discord.JS 导入变量。

您的 if 缺少一些 {},它们应按如下方式使用。:

if(message.channel instanceof Discord.DMChannel) {
   //If the channel IS a DMChannel
} else return;

仅供参考,如果您打算执行多个命令,我会使用一个开关,以及一种将 message.content 转换为参数(字符串数组)的方法。

message.channel.get 不是东西,使用 client.channels.cache.get。变量 CWDI / WDID 前面需要有 var

然后,您需要为 awaitMessages 函数添加过滤器以及最大消息数、时间限制和最少消息数。此外,您还需要 thencatch,所以现在您的代码可能如下所示

if(message.channel instanceof Discord.DMChannel) {
    if (message.content === "confess") {
        message.channel.send("OOOOOOoooooo A SECRET??!?!?! WHAT IS IT?!??!")
        message.reply("Um.... theres two servers that this bot works on. 1: Loves in the snow or 2:?Moomins and Shep's Therapy Service?. Pick a number to send it to one of them") 
        const filter = m => m.author == message.author;
        message.channel.awaitMessages(filter, {/* whatever your parameters/limits are */})
        .then(col => {
            if (col.content === "2") {
                /** Add in code */
            } else if (col.content === "1") {
                /** Add in code */
            }
        })
        .catch(col => {/** Whatever you want to do if times up. */})
    }
}

您可能需要调整过滤器。