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
相关产品推荐
相关产品推荐

