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

使用Eris开发Discord机器人调用createMessage报错:Invalid file object

问题原因及解决方法

你混淆了Eris中Client.createMessage和Interaction.createMessage的参数格式,导致参数被错误解析为文件对象,触发Invalid file object报错。

你的代码里的i是命令交互对象(比如Slash Command的交互实例),它的createMessage方法参数规则和客户端实例的createMessage不同:

解决方式1:直接回复交互(推荐)

如果只是要回复当前命令的发起者,不需要指定频道ID,直接传入内容或配置对象即可:

export default {
    name: 'test',
    description: 'Pi pi poo poo',
    execute: async (i) => {
        // 简洁写法
        await i.createMessage('Yo');
        // 更规范的对象形式(支持更多配置,比如嵌入、附件等)
        // await i.createMessage({ content: 'Yo' });
    },
};

解决方式2:发送到指定频道

如果确实需要发送到指定的独立频道,要通过机器人的客户端实例调用createMessage:

export default {
    name: 'test',
    description: 'Pi pi poo poo',
    execute: async (i) => {
        await i.client.createMessage('535986994145263663', 'Yo');
    },
};

报错原因说明

当你给Interaction.createMessage传入两个参数时,第一个参数会被当作消息配置对象,第二个参数会被识别为文件参数,但'Yo'不是合法的文件对象结构,因此抛出Invalid file object错误。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.30 14:24:29