【问题标题】:Invalid interaction application command(discord.js slash commands using WOKCommands)无效的交互应用命令(discord.js 斜线命令使用 WOKCommands)
【发布时间】:2021-09-12 05:29:45
【问题描述】:

我正在使用 discord.js 和 WOKCommands 来使用斜杠命令,但是当在 Discord 中输入时它给我一个错误“无效的交互应用程序命令”

这里是命令的代码:

const { MessageEmbed } = require("discord.js");

// Simple command for the message
module.exports = {
    name: "ping",
    slash: "both",
    testOnly: false,
    description: "Command to figure out what your current ping is. Also shows API Latency",
    // Executing the message command
    execute(client, message, cmd, args, Discord) {
        // Creating the Embed const
        const newEmbed = new MessageEmbed()
            // ALL EMBED VALUES
            .setColor("#ffdbac")
            .setTitle("Ping")
            .setDescription("Pong! Latency is **" + (Date.now() - message.createdTimestamp) + "ms**. API Latency is **" + message.client.ws.ping + "ms**")
            .setThumbnail(`https://cometiclachlan.github.io/Uploads/pingpong-removebg.png`)
            .setTimestamp()
            .setFooter("v1.2", `https://cometiclachlan.github.io/Uploads/Checkpoint-removebg.png`);

        message.channel.send(newEmbed);
    },
};

只有当我还需要显示主脚本的代码时,这才是命令的代码。我会这样做的。

【问题讨论】:

    标签: javascript node.js discord discord.js


    【解决方案1】:

    您不能在斜杠命令中使用消息,您需要将其更改为

    const { MessageEmbed } = require("discord.js");
    
    // Simple command for the message
    module.exports = {
        name: "ping",
        slash: "both",
        testOnly: false,
        description: "Command to figure out what your current ping is. Also shows API Latency",
        // Executing the message command
        callback : ({client, message, cmd, args, Discord}) => {
            if (message) {
            // Creating the Embed const
            const newEmbed = new MessageEmbed()
            // ALL EMBED VALUES
            .setColor("#ffdbac")
            .setTitle("Ping")
            .setDescription("Pong! Latency is **" + (Date.now() - message.createdTimestamp) + "ms**. API Latency is **" + client.ws.ping + "ms**")
            .setThumbnail(`https://cometiclachlan.github.io/Uploads/pingpong-removebg.png`)
            .setTimestamp()
            .setFooter("v1.2", `https://cometiclachlan.github.io/Uploads/Checkpoint-removebg.png`);
    
            message.channel.send(newEmbed);
            }
            // Slash Command
            const newEmbed = new MessageEmbed()
            ...
            return newEmbed
        }
    };

    【讨论】:

    • 嗨,在 Stack Overflow 上不鼓励仅代码或仅命令的答案,因为它们没有解释它如何解决问题。请编辑您的答案以解释此代码的作用以及它如何回答问题,以便对有类似问题的人有用。见:How do I write a good answer?
    猜你喜欢
    • 2022-01-25
    • 2021-06-11
    • 1970-01-01
    • 2021-11-12
    • 2021-07-02
    • 2021-11-17
    • 2021-09-16
    • 2021-08-17
    • 2021-11-20
    相关资源
    最近更新 更多