rewrote wgeStart from userselect to stringselect with user prefill

This commit is contained in:
2026-06-10 17:26:45 +02:00
parent 0f5ada6c0f
commit f269e15a76
2 changed files with 89 additions and 35 deletions
+53 -17
View File
@@ -1,4 +1,4 @@
const { ModalBuilder, UserSelectMenuBuilder, TextInputBuilder, EmbedBuilder, TimestampStyles, time } = require("@discordjs/builders");
const { ModalBuilder, UserSelectMenuBuilder, TextInputBuilder, EmbedBuilder, TimestampStyles, time, StringSelectMenuBuilder } = require("@discordjs/builders");
const { SlashCommandBuilder, LabelBuilder, TextInputStyle, MessageFlags } = require("discord.js");
const { mClient } = require("../../..");
require('dotenv').config()
@@ -59,34 +59,70 @@ async function wgeStatus(interaction) {
}
async function wgeStart(interaction) {
const defaultUsers = []
defaultUsers.push(process.env.D_ID)
const db = mClient.db('neo-db')
const participantColl = db.collection('items_wge')
const participants = await participantColl.find({
status: true
}).toArray()
const wgeBaseModal = new ModalBuilder()
.setCustomId('wgeBaseModal')
.setTitle("World's Greatest Expert")
const wgeUserInput = new UserSelectMenuBuilder()
.setCustomId('wgeUserInput')
const options = [
{
label: 'RANDOM',
value: process.env.D_ID
}
];
const participantOptions = await Promise.all(
participants.map(async (participant) => {
try {
const member = await interaction.guild.members.fetch(participant.userID);
return {
label: `${member.displayName} (${member.user.username})`,
value: participant.userID
};
} catch {
return null;
}
})
);
options.push(
...participantOptions.filter(option => option !== null)
);
// Using StringSelectMenuBuilder because UserSelectMenuBuilder cannot be filtered for now
const wgeUserCustInput = new StringSelectMenuBuilder()
.setCustomId('wgeCustUserInput')
.setMaxValues(1)
.setMinValues(1)
.setRequired(true)
.addDefaultUsers(process.env.D_ID)
// DefaultUser is randomizer
.addOptions(options)
const wgeTopicInput = new TextInputBuilder()
.setCustomId('wgeTopicInput')
.setStyle(TextInputStyle.Short)
.setRequired(true)
const wgeUserLabel = new LabelBuilder()
.setLabel("Who is YOUR World's Greatest Expert?")
.setDescription('Select them!')
.setUserSelectMenuComponent(wgeUserInput)
const wgeTopicLabel = new LabelBuilder()
.setLabel("And WHAT are they an expert in?")
.setDescription('Tell me!')
.setTextInputComponent(wgeTopicInput)
const wgeCustUserLabel = new LabelBuilder()
.setLabel('WHO is your greatest expert?')
.setDescription('Select them')
.setStringSelectMenuComponent(wgeUserCustInput)
wgeBaseModal
.addLabelComponents(wgeUserLabel, wgeTopicLabel)
.addLabelComponents(wgeCustUserLabel, wgeTopicLabel)
await interaction.showModal(wgeBaseModal)
}
@@ -179,7 +215,7 @@ async function wgeForfeit(interaction) {
const wge = await wgeColl.findOne({
$and: [
{ debug: false },
{ state: 'running'}
{ state: 'running' }
]
})
@@ -357,11 +393,11 @@ module.exports = {
.setDescription('list things')
.addStringOption(o =>
o.setName('thing')
.setDescription('what would you like to be listed')
.addChoices(
{ name: 'participants', value: 'participants'},
{ name: 'history', value: 'history'}
)
.setDescription('what would you like to be listed')
.addChoices(
{ name: 'participants', value: 'participants' },
{ name: 'history', value: 'history' }
)
)
)
,