You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Discord.js v13斜杠命令不使用Embed回复图片附件报错求解

问题原因

  • 方法名拼写错误:交互对象的回复方法为interaction.reply(),代码中错写为interaction.replay(),拼写错误直接导致方法调用失败抛出异常。
  • 回复参数字段错误:Discord.js v13中传递附件的参数字段为files,而非你写的attachment,字段不匹配会导致附件无法被正确识别加载。
  • 你粘贴的代码片段存在语法遗漏,execute异步函数、module.exports对象均未补全闭合的大括号,实际运行时如果存在该问题也会触发语法错误。

可行修复方案

替换你的cook.js命令文件代码为以下内容即可实现斜杠命令直接回复图片附件的需求:

const { SlashCommandBuilder } = require('@discordjs/builders');
const { MessageAttachment } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('cook')
        .setDescription('aaa'),
    async execute(interaction) {
        const imagecook = new MessageAttachment('https://cdn.discordapp.com/attachments/587243063932354560/861940902359728128/gurucooking_long.png');
        await interaction.reply({ files: [imagecook] });
    }
};

上述代码会直接将图片作为消息附件发送,不需要额外依赖Embed实现。

内容的提问来源于stack exchange,提问作者rainmoon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.02 21:48:02