【问题标题】:"This interaction failed" error in command (discord.js)命令中的“此交互失败”错误(discord.js)
【发布时间】:2022-01-26 10:39:09
【问题描述】:

我正在处理 discord.js 中的随机整数斜杠命令

它应该像这样工作:
Discord 用户:/randominteger 最小:1 最大:10

机器人:(嵌入)
随机数
4
1 - 10

但机器人只是说“此交互失败”

我不知道为什么机器人会这样说。 有人可以解释它是如何发生的以及如何解决它吗?

const { SlashCommandBuilder, SlashCommandStringOption } = require('@discordjs/builders');
const {  MessageEmbed  } = require('discord.js')
const color = "#ffed47"


module.exports = {
    data: new SlashCommandBuilder()
        .setName('randominteger')
        .setDescription('Replies with a random integer!')
        .addIntegerOption(option =>
            option.setName('minimal')
                .setDescription('The minimal integer for the random integer')
                .setRequired(true))
        .addIntegerOption(option =>
            option.setName('maximal')
                .setDescription('The maximal integer for the random integer')
                .setRequired(true)),
    async execute(interaction) {
        const minimal = interaction.options.getInteger("minimal")
        const maximal = interaction.options.getInteger("maximal")
        minimal = Math.ceil(minimal)
        maximal = Math.floor(maximal)
        const randomNumber = Math.floor(Math.random() * (maximal+0.1 - minimal) + minimal);

        const random = new MessageEmbed()
        .setColor(color)
        .setTitle("Random Number")
        .setDescription(String(randomNumber))
        .setFooter(String(minimal) + " - " + String(maximal))
        await interaction.reply({embeds : [random]})
    },
};

【问题讨论】:

    标签: discord.js slash


    【解决方案1】:

    对不起,我只是没有正确执行命令xd

    它工作了.. 1 件事,你需要将最小和最大变量更改为“var”而不是“const”(因此可以使用最小和最大变量)

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2021-09-16
    • 2021-12-31
    • 2021-10-19
    • 1970-01-01
    • 2021-11-20
    • 2021-06-06
    相关资源
    最近更新 更多