【问题标题】:discord.js v13 slash command interaction faileddiscord.js v13 斜杠命令交互失败
【发布时间】:2022-01-07 05:34:26
【问题描述】:

命令未运行,我收到“交互失败”错误。

请告诉我哪个文件给出了错误,我该怎么做?

index.js:

client.commands = new Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.data.name, command);
}

client.once('ready', () => {
    console.log('봇이 준비됐습니다!');
});

client.on('interactionCreate', async interaction => {
    if (!interaction.isCommand()) return interaction.reply({content: '없는 명령어입니다...', ephemeral: true });

    const command = client.commands.get(interaction.commandName);

    if (!command) return interaction.reply({ content: '명령을 실행하는 데 실패했습니다...', ephemeral: true });

    try {
        await command.execute(interaction);
    } catch (error) {
        console.error(error);
        return interaction.reply({ content: '명령을 실행하는 데 실패했습니다...', ephemeral: true });
    }
});

s();
keepAlive();
client.login(token);

命令/help.js:

    async execute(interaction) {
    const helpembed = new MessageEmbed()
      .setColor('red')
      .setTitle('명령어')
        return interaction.reply({embeds: [helpembed]});
    },

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    您的代码有几处问题

    文件help.js

    • 您是否导入了 MessageEmbed 构造函数:const { MessageEmbed } = require('discord.js');
    • 你不能做.setColor('red'),你必须做.setColor('#ff0000')

    文件index.js

    • const command = client.commands.get(interaction.commandName); 你为什么要在命令中获取我们的交互?也许您应该尝试使用const command = client.interactions.get(interaction.commandName);(如果声明了交互集合)

    有关错误的更多详细信息,请检查您的控制台并在您可以访问它时提供错误。

    【讨论】:

      猜你喜欢
      • 2021-10-19
      • 2022-01-07
      • 2021-12-31
      • 1970-01-01
      • 2022-01-03
      • 2021-06-06
      • 2021-07-02
      • 2022-01-09
      • 2021-11-09
      相关资源
      最近更新 更多