modal select menu

const allTextChannels = interaction.guild.channels.cache.filter(c => c.type === ChannelType.GuildText || c.type === ChannelType.GuildForum);
const channels = allTextChannels.filter(c => allowedChannelIds.includes(c.id));

const options = channels.map((c, i) =>
new StringSelectMenuOptionBuilder()
.setLabel(c.name)
.setValue(c.id)
.setDefault(i === 0) // first as default
);

const modal = new ModalBuilder()
.setCustomId(`create_modal`)
.setTitle('Create Private Thread')
.addLabelComponents(
new LabelBuilder()
.setLabel('In Channel')
.setStringSelectMenuComponent(
new StringSelectMenuBuilder()
.setCustomId('channelSelect')
.addOptions(options)
)
)
.addLabelComponents(
new LabelBuilder()
.setLabel('Thread message')
.setTextInputComponent(
new TextInputBuilder()
.setCustomId('createThreadMessage')
.setStyle(TextInputStyle.Paragraph)
)
);
await interaction.showModal(modal);
const allTextChannels = interaction.guild.channels.cache.filter(c => c.type === ChannelType.GuildText || c.type === ChannelType.GuildForum);
const channels = allTextChannels.filter(c => allowedChannelIds.includes(c.id));

const options = channels.map((c, i) =>
new StringSelectMenuOptionBuilder()
.setLabel(c.name)
.setValue(c.id)
.setDefault(i === 0) // first as default
);

const modal = new ModalBuilder()
.setCustomId(`create_modal`)
.setTitle('Create Private Thread')
.addLabelComponents(
new LabelBuilder()
.setLabel('In Channel')
.setStringSelectMenuComponent(
new StringSelectMenuBuilder()
.setCustomId('channelSelect')
.addOptions(options)
)
)
.addLabelComponents(
new LabelBuilder()
.setLabel('Thread message')
.setTextInputComponent(
new TextInputBuilder()
.setCustomId('createThreadMessage')
.setStyle(TextInputStyle.Paragraph)
)
);
await interaction.showModal(modal);
36 Replies
d.js toolkit
d.js toolkit•2w ago
Mulo
MuloOP•2w ago
errors I get:
CombinedPropertyError (1)
Received one or more errors
input.component
| CombinedError (7)
| Received one or more errors
|
| 1 CombinedPropertyError (2)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
| |
| | input.style
| | | [MissingPropertyError: style]
|
| 2 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 3 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 4 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 5 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 6 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.options
| | | [ExpectedConstraintError: s.array(T).lengthGreaterThanOrEqual()]
|
| 7 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
CombinedPropertyError (1)
Received one or more errors
input.component
| CombinedError (7)
| Received one or more errors
|
| 1 CombinedPropertyError (2)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
| |
| | input.style
| | | [MissingPropertyError: style]
|
| 2 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 3 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 4 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 5 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
|
| 6 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.options
| | | [ExpectedConstraintError: s.array(T).lengthGreaterThanOrEqual()]
|
| 7 CombinedPropertyError (1)
| | Received one or more errors
| |
| | input.type
| | | [ExpectedValidationError: s.literal(V)]
at _ObjectValidator.handleIgnoreStrategy (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2119:72)
at _ObjectValidator.handleStrategy (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:1983:47)
at _ObjectValidator.handle (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2089:17)
at _ObjectValidator.parse (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:972:90)
at LabelBuilder.toJSON (/home/ubuntu/node_modules/@discordjs/builders/dist/index.js:1759:20)
at /home/ubuntu/node_modules/@discordjs/builders/dist/index.js:2857:64
at Array.map (<anonymous>)
at ModalBuilder.toJSON (/home/ubuntu/node_modules/@discordjs/builders/dist/index.js:2857:35)
at ButtonInteraction.showModal (/home/ubuntu/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:402:46)
at _ObjectValidator.handleIgnoreStrategy (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2119:72)
at _ObjectValidator.handleStrategy (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:1983:47)
at _ObjectValidator.handle (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:2089:17)
at _ObjectValidator.parse (/home/ubuntu/node_modules/@sapphire/shapeshift/dist/cjs/index.cjs:972:90)
at LabelBuilder.toJSON (/home/ubuntu/node_modules/@discordjs/builders/dist/index.js:1759:20)
at /home/ubuntu/node_modules/@discordjs/builders/dist/index.js:2857:64
at Array.map (<anonymous>)
at ModalBuilder.toJSON (/home/ubuntu/node_modules/@discordjs/builders/dist/index.js:2857:35)
at ButtonInteraction.showModal (/home/ubuntu/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:402:46)
Mafia
Mafia•2w ago
what is options defined as nv
Mulo
MuloOP•2w ago
const options = channels.map((c, i) =>
new StringSelectMenuOptionBuilder()
.setLabel(c.name)
.setValue(c.id)
.setDefault(i === 0) // first as default
);
const options = channels.map((c, i) =>
new StringSelectMenuOptionBuilder()
.setLabel(c.name)
.setValue(c.id)
.setDefault(i === 0) // first as default
);
ai says is something about labelBuilder, but at the same it has not up to date info on it since it's recent
Mafia
Mafia•2w ago
how many channels are your trying to add? as options
Mulo
MuloOP•2w ago
that can be dynamic actually, what's the cap shoudl I put in? 25?
d.js docs
d.js docs•2w ago
tag suggestion for @Mulo: discord.js includes multiple sub-packages, installing these separately can mess with internal code:
npm uninstall discord-api-types @discordjs/rest @discordjs/builders
yarn remove discord-api-types @discordjs/rest @discordjs/builders
pnpm remove discord-api-types @discordjs/rest @discordjs/builders
npm uninstall discord-api-types @discordjs/rest @discordjs/builders
yarn remove discord-api-types @discordjs/rest @discordjs/builders
pnpm remove discord-api-types @discordjs/rest @discordjs/builders
Mafia
Mafia•2w ago
yes, string select has a max of 25
Amgelo
Amgelo•2w ago
looks like you're importing from /builders that often messes up with validations
Mulo
MuloOP•2w ago
I mean sometimes it works tho most of the time actually
Amgelo
Amgelo•2w ago
ĀÆ\_(惄)_/ĀÆ only took twice it's a common issue here, not sure when it does break and when not but it does
Mulo
MuloOP•2w ago
great šŸ˜„
Amgelo
Amgelo•2w ago
just import from djs and see if it fixes it
Mulo
MuloOP•2w ago
i do that already
Amgelo
Amgelo•2w ago
and you don't have the builders package installed separately?
Mulo
MuloOP•2w ago
MessageAttachment,
ModalBuilder, // Replaces Modal in v14
TextInputBuilder, // Replaces TextInputComponent in v14
TextInputStyle,
MessageSelectOptionBuilder, // Replaces MessageSelectOptionData in v14

TextDisplayBuilder,
LabelBuilder,
UserSelectMenuBuilder,
RoleSelectMenuBuilder,
ChannelSelectMenuBuilder,
MentionableSelectMenuBuilder,
StringSelectMenuOptionBuilder,
} = require('discord.js');
MessageAttachment,
ModalBuilder, // Replaces Modal in v14
TextInputBuilder, // Replaces TextInputComponent in v14
TextInputStyle,
MessageSelectOptionBuilder, // Replaces MessageSelectOptionData in v14

TextDisplayBuilder,
LabelBuilder,
UserSelectMenuBuilder,
RoleSelectMenuBuilder,
ChannelSelectMenuBuilder,
MentionableSelectMenuBuilder,
StringSelectMenuOptionBuilder,
} = require('discord.js');
the fact that most of the times works, it must mean (hopefully) that is how I format data. Wanted to double check here
Amgelo
Amgelo•2w ago
^^ mostly asking because of this:
at ModalBuilder.toJSON (/home/ubuntu/node_modules/@discordjs/builders/dist/index.js:2857:35)
your modalbuilder goes directly to /builders, doesn't pass through discord.js could be a consequence of toJSON not defined in discord.js though, so it's better to confirm
Mulo
MuloOP•2w ago
how to check?
Amgelo
Amgelo•2w ago
in your package.json
Mulo
MuloOP•2w ago
{
"name": "ubuntu",
"version": "1.0.0",
"type": "module",
"dependencies": {
"discord.js": "^14.24.2",
"dotenv": "^17.2.1",
"flag-icons": "^7.5.0",
"mongo-sanitize": "^1.1.0",
"mongodb": "^6.12.0",
"node-fetch": "^2.7.0",
"redis": "^4.7.0",
"topgg-autoposter": "^2.0.2",
"uuid": "^11.1.0"
}
}
{
"name": "ubuntu",
"version": "1.0.0",
"type": "module",
"dependencies": {
"discord.js": "^14.24.2",
"dotenv": "^17.2.1",
"flag-icons": "^7.5.0",
"mongo-sanitize": "^1.1.0",
"mongodb": "^6.12.0",
"node-fetch": "^2.7.0",
"redis": "^4.7.0",
"topgg-autoposter": "^2.0.2",
"uuid": "^11.1.0"
}
}
cant see any builders around, tho it does ring a bell unless u meant the package.json of discord.js? @Amgelo
Amgelo
Amgelo•2w ago
no, as that's public info are you sure it's that particular modal that's erroring?
Mulo
MuloOP•2w ago
yes i do have
/home/ubuntu/node_modules/discord-api-types
/home/ubuntu/node_modules/discord-api-types
Amgelo
Amgelo•2w ago
yeah since that'll be installed by discord.js it's unrelated
Mulo
MuloOP•2w ago
alright so it's a d.js bug as far as it's known?
Amgelo
Amgelo•2w ago
I'll try to reproduce it locally, I think it looks fine
Mulo
MuloOP•2w ago
could be something on my end too, as sometimes it does work. But errors do not explain much of what's the problem
Amgelo
Amgelo•2w ago
yeah it's working for me locally
Mulo
MuloOP•2w ago
ai says it's the labelbuilder but that's coz it doesnt know latest d.js
Amgelo
Amgelo•2w ago
can you npm ls discord.js
Mulo
MuloOP•2w ago
ubuntu@1.0.0 /home/ubuntu
└── discord.js@14.24.2
ubuntu@1.0.0 /home/ubuntu
└── discord.js@14.24.2
Amgelo
Amgelo•2w ago
and npm ls @discordjs/builders
Mulo
MuloOP•2w ago
ubuntu@vps-10ed1d54:~$ npm list @discordjs/builders
ubuntu@1.0.0 /home/ubuntu
└─┬ discord.js@14.24.2
└── @discordjs/builders@1.13.0
ubuntu@vps-10ed1d54:~$ npm list @discordjs/builders
ubuntu@1.0.0 /home/ubuntu
└─┬ discord.js@14.24.2
└── @discordjs/builders@1.13.0
that's what u meant before?
Amgelo
Amgelo•2w ago
yes, but it looks fine currently try nuking node_modules and reinstalling just in case I can't reproduce the issue with that code
Mulo
MuloOP•2w ago
oh boy I really rather not šŸ˜„
Amgelo
Amgelo•2w ago
you don't have that many packages so it shouldn't take that much plus there's the npm cache
Mulo
MuloOP•2w ago
redis doesnt like uninstalling plenty from other projects

Did you find this page helpful?