【问题标题】:Extract Select Menu values from modal [discord.js]从模态[discord.js]中提取选择菜单值
【发布时间】:2022-08-17 17:57:32
【问题描述】:

我目前正在制作一个基于模式的排序系统并提取 TextInput 工作正常,但是我似乎无法弄清楚如何提取 SelectMenu 数据,因为当前代码只返回一个错误 TypeError: interaction.fields.getSelectMenuValue is not a function

client.on(\'interactionCreate\', async interaction => {
    if (!interaction.isModalSubmit() || !interaction.customId === \'tankform\') return;
    await interaction.reply({ content: \'Your order was received successfully!\', ephemeral: true });
    const IGN = interaction.fields.getTextInputValue(\'minecraft_ign\');
    const Weapon = interaction.fields.getSelectMenuValue(\'weapon_type\');
    const ownedWeapon = interaction.fields.getSelectMenuValue(\'owned_weapon\');
    const ownedTanks = interaction.fields.getSelectMenuValue(\'owned_tanks\');
    const wantedTanks = interaction.fields.getSelectMenuValue(\'wanted_tanks\');
    console.log({IGN, Weapon, ownedWeapon, ownedTanks, wantedTanks})
});

    标签: discord.js modal-dialog bots


    【解决方案1】:

    你的代码看起来不错。问题是 discord.js 还不支持从模式中接收选择菜单。我建议你使用discord-modals。它对我个人有用。

    【讨论】:

    • 我按照上面链接中的指南进行了编辑,以满足我的需要。现在使用 ` const Weapon = modal.getSelectMenuValue('weapon_type');` ,这会产生:TypeError: modal.getSelectMenuValue is not a function
    • 你能发一些代码让我看看你写了什么吗?
    【解决方案2】:

    尝试。

    else If (interaction.type === InteractionType.ModalSubmit)
    { 
    if(interaction.customId === 'yourId') {   
    const IGN = interaction.fields.getTextInputValue('minecraft_ign');
     
    const Weapon = interaction.fields.getSelectMenuValue('weapon_type');
     
    const ownedWeapon = interaction.fields.getSelectMenuValue('owned_weapon');
     
    const ownedTanks = interaction.fields.getSelectMenuValue('owned_tanks');
     
    const wantedTanks = interaction.fields.getSelectMenuValue('wanted_tanks');
     console.log({IGN, Weapon, ownedWeapon, ownedTanks, wantedTanks}) }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-12-31
      • 1970-01-01
      • 2022-07-22
      • 1970-01-01
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 2015-05-14
      相关资源
      最近更新 更多