Discord.js: Message.attachments is empty

Created on 8 Nov 2016  路  4Comments  路  Source: discordjs/discord.js

Hi everyone,
I am very happy with your powerful library, but I have an issue. I want to implement a bot for my mathematic-prof. and I need to catch the attachment in the message the user will send.
I saw you implemented the property attachment in the Class Message, but the property is everytime the same:

{
  "_array": null,
  "_keyArray": null
}

This is the view in Discord (The text is the 'optional' comment):

This is my Code:

var Discord = require("discord.js");
var bot = new Discord.Client();

bot.login("*******************************************");

bot.on('ready', () => {
    console.log('I am ready!');
});

bot.on("message", msg => {
    var prefix = "!";
    var args = stringArgv.parseArgsStringToArgv(msg.content);
    var cmd = args[0] || "";
    args = args.filter(a => a !== cmd);

    if (msg.author.bot) return;
    if (!msg.content.startsWith(prefix)) return;

    if(cmd.startsWith(prefix + "att")){
        console.log(JSON.stringify(msg.attachments, null, 2));
    }
});

darkson95

question (please use Discord instead)

Most helpful comment

@darkson95 i believe this should answer your question

All 4 comments

The property 'embeds' is unfortunately an empty Array.

This is my message:

{
  "channel": {
    "type": "text",
    "id": "245255367804583936",
    "name": "DiscordBot",
    "position": 6,
    "permissionOverwrites": {
      "_array": null,
      "_keyArray": null
    },
    "topic": "",
    "lastMessageID": "245848349444407298",
    "guild": {
      "members": {
        "_array": null,
        "_keyArray": null
      },
      "channels": {
        "_array": null,
        "_keyArray": null
      },
      "roles": {
        "_array": null,
        "_keyArray": null
      },
      "available": true,
      "id": "**************",
      "name": ""*************",
      "icon": "947fd9aed0b49ec2feb0eacba4b0162a",
      "splash": null,
      "region": ""**************",",
      "memberCount": 30,
      "presences": {
        "_array": null,
        "_keyArray": null
      },
      "features": [],
      "emojis": {
        "_array": null,
        "_keyArray": null
      },
      "afkTimeout": 3600,
      "afkChannelID": "218442199325474816",
      "verificationLevel": 1,
      "joinedTimestamp": 1478542701109,
      "ownerID": ""*************",
      "_rawVoiceStates": {
        "_array": null,
        "_keyArray": null
      }
    },
    "messages": {
      "_array": null,
      "_keyArray": null
    },
    "_typing": {}
  },
  "id": "245848896910131200",
  "type": "DEFAULT",
  "content": "",
  "author": {
    "id": "116864531325517832",
    "username": "darkson95",
    "discriminator": "8982",
    "avatar": "1bfcb1b91ddb1caee7da6d903e1cc0a3",
    "bot": false
  },
  "member": {
    "guild": {
      "members": {
        "_array": null,
        "_keyArray": null
      },
      "channels": {
        "_array": null,
        "_keyArray": null
      },
      "roles": {
        "_array": null,
        "_keyArray": null
      },
      "available": true,
      "id": "218441092381540352",
      "name": "Wurst-Kun",
      "icon": "947fd9aed0b49ec2feb0eacba4b0162a",
      "splash": null,
      "region": "frankfurt",
      "memberCount": 30,
      "presences": {
        "_array": null,
        "_keyArray": null
      },
      "features": [],
      "emojis": {
        "_array": null,
        "_keyArray": null
      },
      "afkTimeout": 3600,
      "afkChannelID": "218442199325474816",
      "verificationLevel": 1,
      "joinedTimestamp": 1478542701109,
      "ownerID": "116864531325517832",
      "_rawVoiceStates": {
        "_array": null,
        "_keyArray": null
      }
    },
    "user": {
      "id": "116864531325517832",
      "username": "darkson95",
      "discriminator": "8982",
      "avatar": "1bfcb1b91ddb1caee7da6d903e1cc0a3",
      "bot": false
    },
    "_roles": [
      "218445102924824576"
    ],
    "serverDeaf": false,
    "serverMute": false,
    "selfMute": true,
    "selfDeaf": false,
    "voiceSessionID": "5190eace11db29c8deb6b2c0ac5934fd",
    "voiceChannelID": "218442786913910794",
    "speaking": false,
    "nickname": null,
    "joinedTimestamp": 1472150814963
  },
  "pinned": false,
  "tts": false,
  "nonce": null,
  "system": false,
  "embeds": [],
  "attachments": {
    "_array": null,
    "_keyArray": null
  },
  "createdTimestamp": 1478685344675,
  "editedTimestamp": null,
  "mentions": {
    "users": {
      "_array": null,
      "_keyArray": null
    },
    "roles": {
      "_array": null,
      "_keyArray": null
    },
    "channels": {
      "_array": null,
      "_keyArray": null
    },
    "everyone": false
  },
  "_edits": []
}

@darkson95 i believe this should answer your question

To expand on Gus's comment, message.attachments is a collection mapped by attachment ID. Because attachments can be circular, it can be hard to use JSON.stringify on them, I suggest grabbing the values you need from an attachment and JSON.stringifying them instead.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Acaretia picture Acaretia  路  3Comments

Alipoodle picture Alipoodle  路  3Comments

kvn1351 picture kvn1351  路  3Comments

Lombra picture Lombra  路  3Comments

Brawaru picture Brawaru  路  3Comments