【问题标题】:Slash Command "Echo" Command Discord.JS斜线命令 "Echo" 命令 Discord.JS
【发布时间】:2022-01-25 17:53:26
【问题描述】:

我希望命令做的就是说出我们希望机器人说的话。

示例:/echo 测试
并且机器人应该响应:测试

但我不知道该怎么做

这是我的代码:

const { SlashCommandBuilder, SlashCommandStringOption } = require('@discordjs/builders');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('echo')
        .setDescription('Replies with your input!')
        .addStringOption(option =>
            option.setName('input')
                .setDescription('The input to echo back')
                .setRequired(true)),
    async execute(interaction) {
        await interaction.send(input)
    },
};

【问题讨论】:

    标签: node.js discord.js slash


    【解决方案1】:

    您必须使用CommandInteraction.options 并在其上使用.getString() 才能获得输入

    async execute(interaction) {
        const input = interaction.options.getString("input")
        await interaction.send(input)
    }
    

    【讨论】:

      猜你喜欢
      • 2021-06-11
      • 2021-11-17
      • 2021-08-17
      • 2022-01-14
      • 2021-09-12
      • 2021-11-12
      • 2022-01-07
      • 2021-08-28
      • 2022-01-15
      相关资源
      最近更新 更多