#Cannot read property 'persistentData' from undefined

6 messages · Page 1 of 1 (latest)

inland elbow
#

nyallo
upon running a command, 'an unexpected error occurred' appears in chat, and when i hover over that message it comes up with TypeError: Cannot read property "persistentData" from undefined. it next specifies that
let pData = event.server.persistentData
is the problem

ServerEvents.commandRegistry(event => {
    const { commands: Commands, arguments: Arguments } = event
    event.register(
        Commands.literal('permadeath')
            .requires(src => src.hasPermission(2))
            .then(Commands.argument('boolean', Arguments.BOOLEAN.create(event))
            .executes(ctx => {
                let pData = event.server.persistentData
                const boolean = Arguments.BOOLEAN.getResult(ctx, "boolean");
                console.log(boolean)
                if (boolean) {
                    console.log('when the permadeath is true')
                    pData.permadeath = true
                } else {
                    pData.permadeath = false
                    console.log('when the permadeath is false')
                    console.log(pData.permadeath)
                }
                return 1;
            })))
})```
surreal ridgeBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

inland elbow
#

bump

rough narwhal
#

there is no "server" off the "event" object in command registry, instead youll have to utilize and got through the context of the command which in your case will be the "ctx" like so js ctx.source.server.persistentData

#

same thing if you want to get the potential player whos running the command js let player = ctx.source.player