无法找出导致问题的原因

时间:2019-11-17 11:51:04

标签: javascript node.js discord discord.js

我最近问了一个问题,该如何使用每服务器命令设置跨服务器机器人。有人说我可以使用quick.db,然后将这段代码放在他的答案中:

client.on("message", message => {
    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();
    if(command == "setautorole"){
        let roleName = args.slice(0).join(" ");
        let role = message.guild.roles.find(role => role.name == roleName).catch(message.reply("Couldn't find that role"),
        db.set(`autorole_${message.guild.id}`, role.id)
    }
    if(command == "unsetautorole"){
        db.delete(`autorole_${message.guild.id})
    }
    if(command == "setwelcomechannel"){
        let channelName = args.slice(0).join(" ");
        let channel = message.guild.channels.find(channel => channel.name == channelName).catch(message.reply("Couldn't find that channel")
        db.set(`welcomechannel_${message.guild.id}`, channel.id)
    }
    if(command == "unsetwelcomechannel"){
        db.delete(`welcomechannel_${message.guild.id})
    }
})
client.on("guildMemberAdd", member => {
    let roleId = db.get(`autorole_${member.guild.id}`);
    if(roleId) member.addRole(roleId).catch(console.error);
    let channelId = db.get(`welcomechannel_${member.guild.id}`);
    if(channelId) channel = member.guild.channels.get(channelId).catch(console.error);
    if(channel) channel.send("x")
})

问题是,我遇到很多错误。 https://imgur.com/a/zUxx9TK

我需要在哪里以及什么位置修复所说的错误?

2 个答案:

答案 0 :(得分:0)

client.on("message", message => {
    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();
    if(command == "setautorole"){
        let roleName = args.slice(0).join(" ");
        let role = message.guild.roles.find(role => role.name == roleName).catch(message.reply("Couldn't find that role"))
        db.set(`autorole_${message.guild.id}`, role.id)
    }
    if(command == "unsetautorole"){
        db.delete(`autorole_${message.guild.id}`)
    }
    if(command == "setwelcomechannel"){
        let channelName = args.slice(0).join(" ");
        let channel = message.guild.channels.find(channel => channel.name == channelName).catch(message.reply("Couldn't find that channel"))
        db.set(`welcomechannel_${message.guild.id}`, channel.id)
    }
    if(command == "unsetwelcomechannel"){
        db.delete(`welcomechannel_${message.guild.id}`)
    }
})
client.on("guildMemberAdd", member => {
    let roleId = db.get(`autorole_${member.guild.id}`);
    if(roleId) member.addRole(roleId).catch(console.error);
    let channelId = db.get(`welcomechannel_${member.guild.id}`);
    if(channelId) channel = member.guild.channels.get(channelId).catch(console.error);
    if(channel) channel.send("x")
})

答案 1 :(得分:-1)

在第18行,您忘记了关闭模板字符串:)