#TypeError .addUserOption(...).setRequired is not a function

1 messages · Page 1 of 1 (latest)

lapis lance
#

TypeError: (intermediate value).setName(...).setDescription(...).addUserOption(...).setRequired is not a function

dense bough
#

can you show your full code?

uncut vigil
#

you have to call setRequired on the UserOption

lapis lance
#

I typed it wrong

#

I did call it with ()

dense bough
#

yeah

lapis lance
#

nvm

#

option => is the same as .addUserOption(...) right?

#

option.setRequired()

dense bough
#

in your code i believe so

#

err actually no

lapis lance
#

hmm...

#

I changed it to chain off the actual .addUserOption(...) function

#
.addUserOption(option => 
            option.setName("user")
                .setDescription("The user to timeout")
).setRequired(true)
#

instead of

#
.addUserOption(option => 
            option.setName("user")
                .setDescription("The user to timeout")
                .setRequired(true)
)
uncut vigil
#

that's what I meant with "call it on the UserOption"

lapis lance
#

but it's still not working

dense bough
#

same error?

uncut vigil
#

did you save the file?

lapis lance
#

I pressed Ctrl+S and tried it again

#

Still the same error

#

TypeError: (intermediate value).setName(...).setDescription(...).addUserOption(...).setRequired is not a function

uncut vigil
#

follow the stack trace

lapis lance
#
TypeError: (intermediate value).setName(...).setDescription(...).addUserOption(...).setRequired is not a function
    at Object.<anonymous> (/home/runner/BetterMinecraft/commands/mute.js:9:11)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Function.Module._load (node:internal/modules/cjs/loader:822:12)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/home/runner/BetterMinecraft/deploy-commands.js:10:21)
    at Module._compile (node:internal/modules/cjs/loader:1101:14)
uncut vigil
#

mute.js:9

lapis lance
#

).setRequired(true)

uncut vigil
#

and what's before that

lapis lance
#
const { SlashCommandBuilder } = require("@discordjs/builders")

const data = new SlashCommandBuilder()
        .setName("mute")
        .setDescription("Mute/timeout someone!")
        .addUserOption(option => 
            option.setName("user")
                .setDescription("The user to timeout")
        ).setRequired(true)
#

lines 1-9

uncut vigil
#

you are still calling setRequired on the SlashCommandBuilder here

lapis lance
#

so how do I fetch the UserOption

dense bough
uncut vigil
#

move the setRequired call inside the ()

lapis lance
#

Back to after .setDescription(...)?

uncut vigil
#

why would you do that? setDescription returns the SlashCommandBuilder instance

#

you want to call setRequired on the option

lapis lance
#

so

#

I have 3 properties I need on UserOption

#

.setName("user"), .setDescription("The user to timeout"), and .setRequired(true)

uncut vigil
#

yes

lapis lance
#

so option.setRequired(true)

#

do setName and setDescription need UserOption

#

because then what does setRequired return

dense bough
#

nothing

#

it returns void

uncut vigil
#

no, it returns the option

lapis lance
#

(also, why can't I find this on the docs?)

dense bough
#

oh i thought you were talking about the

uncut vigil
#

all builder setters return this

lapis lance
#

(it's just not there when I search.)

dense bough
#

discordjs/builders isn't on the docs iirc

uncut vigil
#

it is

dense bough
#

oh its not on the discord one

lapis lance
#

thx

#

but if all builder setters return option

#

then why doesn't setRequired get it at the end?

dense bough
#

addUserOption returns the SlashCommandBuilder

#

so essentially you're trying to setRequired on the slash command

lapis lance
#

................

#

With an arrow function?

dense bough
#

oh wait

#

are you still encountering an error

lapis lance
#

Finding out...

#

Uh

#

I think it's an error somewhere else in my code...

dense bough
#

well

#

show the line

lapis lance
#
[
  {
    "code": "invalid_type",
    "expected": "string",
    "received": "undefined",
    "path": [],
    "message": "Required"
  }
]
    at new ZodError (/home/runner/BetterMinecraft/node_modules/zod/lib/ZodError.js:80:28)
    at handleResult (/home/runner/BetterMinecraft/node_modules/zod/lib/types.js:115:21)
    at ZodString.ZodType.safeParse (/home/runner/BetterMinecraft/node_modules/zod/lib/types.js:191:16)
    at ZodString.ZodType.parse (/home/runner/BetterMinecraft/node_modules/zod/lib/types.js:172:27)
    at MixedClass.addChoice (/home/runner/BetterMinecraft/node_modules/@discordjs/builders/dist/index.js:3:8695)
    at /home/runner/BetterMinecraft/commands/mute.js:26:18
    at MixedClass._sharedAddOptionMethod (/home/runner/BetterMinecraft/node_modules/@discordjs/builders/dist/index.js:3:12168)
    at MixedClass.addStringOption (/home/runner/BetterMinecraft/node_modules/@discordjs/builders/dist/index.js:3:11941)
    at Object.<anonymous> (/home/runner/BetterMinecraft/commands/mute.js:22:10)
dense bough
#

and what line is this on

#

at Object.<anonymous> (/home/runner/BetterMinecraft/commands/mute.js:22:10)

#

can you show that line?

lapis lance
#

you might as well see the full code?

dense bough
#

.addChoice requires 2 params

#

on line 25 & 26

#

you're only providing a name and not a value

#

should fix it

lapis lance
#

you can see me editing the code right?

dense bough
#

nope

lapis lance
#

new code:

#
.addStringOption(option =>
            option.setRequired(true)
                .setName("reason")
                .setDescription("The reason for the timeout")
                .addChoice("Foo", "internal_common_1")
                .addChoice("Bar", "internal_common_2")
        )
#

22-28

#

now the bot starts

dense bough
#

no errors?

lapis lance
#

No

#

And it says my test phrase

#

but right now I don't have any functionality

dense bough
#

ok so it works

lapis lance
#

yes

#

You can timeout users with Discord.JS right?

#

maybe I should've used this all along... lol...

#

but I just found a tutorial on it