我收到一个错误,因为它说我的 arg 未定义

时间:2021-06-06 02:27:23

标签: discord discord.js

这是我的 arg 错误,第二个代码块是我的命令代码。它应该做 LTM!c 。当我使用不同的命令处理程序设置它时它正在工作,但它仍然应该工作。最后一个是我的命令处理程序。 错误:

let channelName = args[0];
                              ^

TypeError: Cannot read property '0' of undefined

代码:

        let channelName = args[0];
        let channelTime = args[1];
        if(!channelTime) return message.channel.send(" no time")
        if(!channelName) return message.channel.send("no name") // YOu can edit this with embeds etc
        let msTime = ms(channelTime);

        const categoryID = message.member.guild.channels.cache.find(c => c.id == `850420491915493387`) //add category id

        if (!categoryID) return message.channel.send('No Category made!')
        message.guild.channels.create(channelName, { type: 'text' }).then(
            (createdChannel) => {

                createdChannel.setParent(categoryID).then(
                    (settedParent) => {

                        settedParent.updateOverwrite(message.guild.roles.cache.find(x => x.name === '@everyone'), {
                            SEND_MESSAGES: false,
                            VIEW_CHANNEL: false  // YOu can make this public or private channel by making false or true
                        });

                        setTimeout(() => {
                            const deleted = message.guild.channels.cache.find(channel => channel.name.toLowerCase() === args[0])
                            deleted.delete()  

                        }, msTime)
                    }
// IGnore these ones its just for error bs
                ).catch(err => {
                    // if err console err
                    return console.log(err)
                });
            }
        ).catch(err => {
// if err console err
            return console.log(err)
        });
    })```



Cmd Handler:
const { prefix } = require('./config.json')

module.exports = (client, aliases, callback) => {
    if (typeof aliases === 'string') {
        aliases = [aliases]
    }

    client.on('message', (message) => {
        const { content } = message

        aliases.forEach((alias) => {
            const command = `${prefix}${alias}`

            if (content.startsWith(`${command} `) || content === command) {
                console.log(`Running the command ${command}`)
                callback(message)
            }
        })
    })
}

1 个答案:

答案 0 :(得分:0)

我找到了答案。我没有通过我的命令处理程序传递参数。