#TypeError .addUserOption(...).setRequired is not a function
1 messages · Page 1 of 1 (latest)
can you show your full code?
you have to call setRequired on the UserOption
yeah
wait
nvm
option => is the same as .addUserOption(...) right?
option.setRequired()
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)
)
that's what I meant with "call it on the UserOption"
but it's still not working
same error?
did you save the file?
I pressed Ctrl+S and tried it again
Still the same error
TypeError: (intermediate value).setName(...).setDescription(...).addUserOption(...).setRequired is not a function
follow the stack trace
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)
mute.js:9
).setRequired(true)
and what's before that
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
you are still calling setRequired on the SlashCommandBuilder here
so how do I fetch the UserOption
do what you did here
move the setRequired call inside the ()
Back to after .setDescription(...)?
why would you do that? setDescription returns the SlashCommandBuilder instance
you want to call setRequired on the option
so
I have 3 properties I need on UserOption
.setName("user"), .setDescription("The user to timeout"), and .setRequired(true)
yes
so option.setRequired(true)
do setName and setDescription need UserOption
because then what does setRequired return
no, it returns the option
(also, why can't I find this on the docs?)
oh i thought you were talking about the
all builder setters return this
(it's just not there when I search.)
discordjs/builders isn't on the docs iirc
oh its not on the discord one
thx
but if all builder setters return option
then why doesn't setRequired get it at the end?
addUserOption returns the SlashCommandBuilder
so essentially you're trying to setRequired on the slash command
[
{
"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)
and what line is this on
at Object.<anonymous> (/home/runner/BetterMinecraft/commands/mute.js:22:10)
can you show that line?
.addChoice requires 2 params
on line 25 & 26
you're only providing a name and not a value
should fix it
you can see me editing the code right?
nope
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
no errors?
ok so it works