繁体   English   中英

Discord.js 尝试向用户发送消息时出现“意外标识符”

[英]Discord.js “Unexpected identifier” when trying to DM a user

我正在为服务器制作自定义机器人,并制作了禁止词列表。 我正在努力让它静音,直到他们再次同意规则。 这是代码:

if(msg.split(" ").includes("asdf")){
  if(msg.deletable){
      msg.delete()
  if(!msg.member.roles.cache.get("777167323232469002")
     msg.member.send("You have been muted for saying a banned word. Please visit the rules and read all of our rules. React with a checkmark if you agree to all of the rules.")
          .then(sent =>{
            sent.react("✔️")
            let muted = msg.guild.roles.cache.get("759883236322574376")
            msg.member.roles.add(muted)
            sent.awaitReactions((reaction,user) => (reaction.emoji.name == "✔️"),
                        {max: 1}.then(collected => {
                        if(collected.first().emoji.name=="✔️"){
                            msg.member.roles.remove(muted)
                            msg.author.send("Thank you for agreeing to follow our rules. Please keep in mind breaking any rules will result in moderator punishment.")
                        }
            })

        )}
        
  }
  }
}

output 它给了我:

msg.member.send("You have been muted for saying a banned word. Please visit the rules and read all of our rules. React with a checkmark if you agree to all of the rules.")
^^^

SyntaxError: Unexpected identifier

我不确定如何解决这个问题,而且我是 JavaScript 的新手。 有人可以帮忙吗?

你的语法到处都是。 我建议安装 linter,使用具有语法突出显示的 IDE 或两者兼而有之。 这会让你知道你是否缺少括号等等。 我可以为 IDE 推荐Visual Studio Code

我更正了语法,但请确保按照我上面的建议进行操作。

if (msg.split(" ").includes("asdf")) {
    if (msg.deletable) msg.delete();
    if (!msg.member.roles.cache.get("777167323232469002")) {
        msg.member.send("You have been muted for saying a banned word. Please visit the rules and read all of our rules. React with a checkmark if you agree to all of the rules.")
            .then(sent => {
                sent.react("✔️");
                let muted = msg.guild.roles.cache.get("759883236322574376");
                msg.member.roles.add(muted);
                sent.awaitReactions((reaction, user) => (reaction.emoji.name == "✔️"), { max: 1 })
                    .then(collected => {
                        if (collected.first().emoji.name == "✔️") {
                            msg.member.roles.remove(muted);
                            msg.author.send("Thank you for agreeing to follow our rules. Please keep in mind breaking any rules will result in moderator punishment.");
                        }
                    })
            })
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM