NodeJS 如何定义和引用在javascript discord.js的stringOption文本参数中输入的文本?

rnmwe5a2  于 2023-02-03  发布在  Node.js
关注(0)|答案(1)|浏览(79)

我试图让一个不和谐的机器人只是回复用户输入的确切消息。我有它的设置,所以命令看起来像“/tsay text:TextExample”是字符串选项,如果它工作,它会回复用户输入的“TextExample”。我试图得到文本,但我真的不知道怎么做。任何帮助都是感激的,因为我是JavaScript和discord.js的新手。以下是我目前拥有的

module.exports = {
    data: new SlashCommandBuilder()
    .setName('tsay')
    .setDescription('Replies with the text that was entered (General)')
    .addStringOption(option => 
        option.setName('text')
        .setDescription('Text to be copied')
            .setRequired(true)),

            async execute(interaction, client) {
                const textOption = interaction.getOption('text');
                const Text = textOption.content;
                // Reply with the text
                await interaction.editReply({
                    content: toString(Text)
                });
            } 
}```



I tried searching up how to do it and look at different documentations but I couldn't find anything exactly that could help me solve my issue.
8i9zcol2

8i9zcol21#

实际上我现在找到了一个修复方法。我不得不以不同的方式引用选项。下面是工作正常的更新代码

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

module.exports = {
    data: new SlashCommandBuilder()
    .setName('tsay')
    .setDescription('Replies with the text that was entered (General)')
    .addStringOption(option => 
        option.setName('text')
        .setDescription('Text to be copied')
            .setRequired(true)),

            async execute(interaction, client) {
                const Text = interaction.options.getString('text');

                // Reply with the text
                await interaction.reply({
                    content: Text
                });
            } 
}

相关问题