Discord.js v12测试命令问题需要修复

时间:2020-07-11 17:37:37

标签: javascript discord.js

命令是$test <gamemode,代码中目前有2种游戏模式(即时和自给式),问题是当人写类似$test agsdfasd的东西时,游戏模式中还有其他东西,由于某种原因,它仍然扮演着角色。 我的代码:

client.on("message", message => {

    if (message.content.startsWith(prefix + "test")) {
        let testRole = message.guild.roles.cache.find(role => role.name == "Needs to be tested")
        let Tester = message.guild.roles.cache.find(role => role.name == "Tester")
        let SFTester = message.guild.roles.cache.find(role => role.name == "Self-Feed Tester")
        let Tested = message.guild.roles.cache.find(role => role.name == "TESTED")
        let testChannel = message.guild.channels.cache.find(channel => channel.name == "test")
        const args = message.content.slice(prefix.length + 5).split(/  +/)
        let uReply = args[0];

        if(!testRole) return message.channel.send("There is no role called `Needs to be tested`! Please create that specific role!")
        if(!Tester) return message.channel.send("There is no role called `Tester`! Please create that specific role!")
        if(!SFTester) return message.channel.send("There is no role called `Self-Feed Tester`! Please create that specific role!")
        if(!Tested) return message.channel.send("There is no role called `TESTED` Please create that specific role in CAPS! (this role is for people who fail the test!)")
        if(!testChannel) return message.channel.send("There is no channel called `test`! Please create that specific channel! (The chat where only people with the role `Needs to be tested` will see and the `Tester`.)")
        if (message.member.roles.cache.some(role => role.name === 'Needs to be tested')) return message.channel.send("You already have that role!")
        if (message.member.roles.cache.some(role => role.name === 'TESTED')) return message.channel.send("You were already tested.")

        if(!uReply){ message.channel.send("Please write which type of gamemode you want to be tested for.(`INSTANT`, `SELF-FEED`)\nUsage: `$test INSTANT`")
    } else if(uReply === "INSTANT", "instant") {
        message.member.roles.add(testRole)
        message.channel.send("You have been given `Needs to be tested` role! You will be tested shortly!")
        testChannel.send(`${Tester} please test ${message.author} (INSTANT)!`)
        console.log(`${message.author.tag} used the command $test INSTANT in "${message.guild.name}" | ${message.guild.memberCount}`)
        } else if(uReply === "SELF-FEED", "self-feed", "selffeed") {
            message.member.roles.add(testRole)
            message.channel.send("You have been given `Needs to be tested` role! You will be tested shortly!")
            testChannel.send(`${SFTester} please test ${message.author} (Self-Feed)!`)
            console.log(`${message.author.tag} used the command $test SELF-FEED in "${message.guild.name}" | ${message.guild.memberCount}`)
        } else message.channel.send("That gamemode does not exist for now. We only have instant and self-feed for now.")
    }
})

enter image description here

0 个答案:

没有答案