#sending files

1 messages · Page 1 of 1 (latest)

old gust
#

Currently trying to send a file that is attached to a message, but I get Cannot send an empty message. What have I done wrong here?

If I remove the files property the message sends fine.

  const txtFile = new Blob(['hello world'], { type: 'text/plain' });
  console.log(txtFile);

  return await BOT.rest.sendMessage(data.dmChannelId, {
    content: '222',
    files: [
      {
        name: 'application.txt',
        blob: txtFile,
      },
    ],
  });
 {
   ok: false,
   status: 400,
   body: '{"message": "Cannot send an empty message", "code": 50006}'
 }
tulip sleet
old gust
#

I still get the same thing even with that 😢
on ver "19.0.0-next.b496f4c"

tulip sleet
#

ah you're full v19 right

#

im not so idk

#

my bot process converts to this and sends to proxy

#

proxy reverts and sends to discord

#

prob a bug then maybe?

old gust
ancient seal
#

@past ocean

ancient seal
#

did yall manage to figure this out

old gust
#

Nope not yet

ancient seal
#

worked just fine for me

#

@old gust

old gust
#

just updating to latest dd to test

#

still get the same issue even on latest commit

#

just adding some logs

#

After going through

        async sendMessage (channelId, body) {
            console.log("choo: ", body) // payload is fine
            return await rest.post(rest.routes.channels.messages(channelId), {
                body,
                files: body.files
            });
        },

        async post (url, options) {
            console.log("glue: ", options) // payload is fine (it seems like camelize breaks it)
            return camelize(await rest.makeRequest('POST', url, options));
        },

the payload:

public-discord-bot:dev: {
public-discord-bot:dev:   body: { content: '222', files: [ [Object] ] },
public-discord-bot:dev:   files: [ { name: 'application.txt', blob: [Blob] } ]
public-discord-bot:dev: }

gets converted to

{ body: {} }
ancient seal
#

add a log in makeRequest

#

confirm that its the camelize that breaks it

#

caseethat is quite odd

old gust
#

I'm not actually sure, foodoo logged twice, one time it has its content, and the other time it doesn't. I only send one message, so not sure why foodoo is logged twice?

        async sendMessage (channelId, body) {
            console.log("choo: ", body)
            return await rest.post(rest.routes.channels.messages(channelId), {
                body,
                files: body.files
            });
        },
        async post (url, options) {
            console.log("glue: ", options)
            return camelize(await rest.makeRequest('POST', url, options));
        },
        async makeRequest (method, route, options) {
            console.log("foodoo: ", options)
            ...
public-discord-bot:dev: choo:  {
public-discord-bot:dev:   content: '222',
public-discord-bot:dev:   files: [ { name: 'application.txt', blob: [Blob] } ]
public-discord-bot:dev: }
public-discord-bot:dev: glue:  {
public-discord-bot:dev:   body: { content: '222', files: [ [Object] ] },
public-discord-bot:dev:   files: [ { name: 'application.txt', blob: [Blob] } ]
public-discord-bot:dev: }
public-discord-bot:dev: foodoo:  {
public-discord-bot:dev:   body: { content: '222', files: [ [Object] ] },
public-discord-bot:dev:   files: [ { name: 'application.txt', blob: [Blob] } ]
public-discord-bot:dev: }
public-discord-rest:dev: foodoo:  { body: {} }
public-discord-rest:dev: [REST] error on url: /channels/1094692973918306325/messages
public-discord-rest:dev:  {
public-discord-rest:dev:   ok: false,
public-discord-rest:dev:   status: 400,
public-discord-rest:dev:   body: '{"message": "Cannot send an empty message", "code": 50006}'
public-discord-rest:dev: }
#

it must be camelize though, since that looks to be the last function in the pipeline before running the final makeRequest?

#

The command runs using:

export const stats: AppyCommand = {
  name: 'stats',
  description: 'Displays Appy statistics',
  async execute(interaction) {
    const txtFile = new Blob(['hello world'], { type: 'text/plain' });
    return await BOT.rest.sendMessage('1094692973918306325', {
      content: '222',
      files: [
        {
          name: 'application.txt',
          blob: txtFile,
        },
      ],
    });

Only one request should be going out.

just noticed, when logging req.body in my rest express code

app.all('/*', async (req, res) => {
  if (AUTHORIZATION !== req.headers.authorization) {
    return res.status(401).json({ error: 'Invalid authorization key.' });
  }
  console.log('8auuu: ', req.body);

it is empty there too

ancient seal
#

@past ocean any thoughts on this?

#

my guess is this might not be camelize since if its sent to a proxy, then there is no camelize done on it

past ocean
#

this is send to proxy?

ancient seal
#

his code makes me think its sent to proxy

past ocean
#

if its send to proxy

#

the proxy needs to handle formdata

old gust
#

yep it sends to rest proxy, do you have any idea on how to handle formdata with express?

I've tried using multer middleware to accept all types of data, which fixes the error but doesn't end up sending the text file.

  const upload = multer();
app.all('/*', upload.any(), async (req, res) => {

[Object: null prototype] { payload_json: '{"content":"222"}' }

tulip sleet
#

Or do like in v18