【问题标题】:How do I make a string option automatically selected in Discord.js?如何在 Discord.js 中自动选择字符串选项?
【发布时间】:2022-12-10 22:30:31
【问题描述】:

我一直在研究 Discord 机器人并阅读文档。我对此很陌生,找不到关于该主题的任何 YT 教程,这是代码:

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('test')
        .setDescription('Select a test to use.')
        .addStringOption(option =>
            option
                .setName('type')
                .setDescription('Type of test requested')),

        async execute(interaction) {
            const ptypes = interaction.options.getString('type') ?? 'No reason provided';
            await interaction.reply(`You chose ${ptypes}`);
        },
};
当我输入命令时,它不会自动显示一个框供我输入,而是让我在输入任何内容之前选择名为“测试”的选项。

这是如何工作的:
/test > [click]test > [input]test

这是我希望它工作的方式:
/test > [input]test

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    您可以通过提供 .setRequired() 来完成此操作

    .addStringOption(option =>
                option
                    .setName('type')
                    .setDescription('Type of test requested'))
                    .setRequired(true),
    

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 1970-01-01
      • 1970-01-01
      • 2022-07-06
      • 2013-12-12
      • 1970-01-01
      • 2021-08-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多