Home > Enterprise >  Can't set the bot's avatar discord js
Can't set the bot's avatar discord js

Time:10-06

I saw my friend's discord bot and it can change the avatar so I decided to might as well code that to my bot too(It won't hurt right?). But when I execute the command it did work but it crashes my bot.

Here's my code

    if (message.content == "-scp set avatar scare hamster"){
      let set = clients.user.setAvatar("./scare.jpg");
      let embed = new Discord.MessageEmbed()
      .setTitle("Successfully setted the bots avatar!")
      .setColor("GREEN")
      .setImage("attachment://scare.jpg")
      message.channel.send({embeds: [embed, set], files: [`./scare.jpg`]})
    }else

the error I got when executed

C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:298
      throw new DiscordAPIError(data, res.status, request);
            ^

DiscordAPIError: Invalid Form Body
embeds[1].description: This field is required
    at RequestHandler.execute (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:298:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async RequestHandler.push (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\rest\RequestHandler.js:50:14)
    at async TextChannel.send (C:\Users\1love\Dropbox\My PC (DESKTOP-MEST1TS)\Desktop\Bot Core Assets\SCP bot assets\node_modules\discord.js\src\structures\interfaces\TextBasedChannel.js:171:15) {
  method: 'post',
  path: '/channels/856891414478848002/messages',
  code: 50035,
  httpStatus: 400,
  requestData: {
    json: {
      content: undefined,
      tts: false,
      nonce: undefined,
      embeds: [
        {
          title: 'Successfully setted the bots avatar!',
          type: 'rich',
          description: null,
          url: null,
          timestamp: 0,
          color: 5763719,
          fields: [],
          thumbnail: null,
          image: {
            url: 'attachment://scare.jpg',
            proxyURL: undefined,
            height: undefined,
            width: undefined
          },
          author: null,
          footer: null
        },
        {
          title: null,
          type: 'rich',
          description: null,
          url: null,
          timestamp: null,
          color: null,
          fields: [],
          thumbnail: null,
          image: null,
          author: null,
          footer: null
        }
      ],
      components: undefined,
      username: undefined,
      avatar_url: undefined,
      allowed_mentions: undefined,
      flags: undefined,
      message_reference: undefined,
      attachments: undefined,
      sticker_ids: undefined
    },
    files: [
      {
        attachment: './scare.jpg',
        name: 'scare.jpg',
        file: ReadStream {
          fd: null,
          path: 'C:\\Users\\1love\\Dropbox\\My PC (DESKTOP-MEST1TS)\\Desktop\\Bot Core Assets\\SCP bot assets\\scare.jpg',
          flags: 'r',
          mode: 438,
          start: undefined,
          end: Infinity,
          pos: undefined,
          bytesRead: 15761,
          closed: true,
          _readableState: ReadableState {
            objectMode: false,
            highWaterMark: 65536,
            buffer: [BufferList],
            length: 0,
            pipes: [],
            flowing: true,
            ended: true,
            endEmitted: true,
            reading: false,
            constructed: true,
            sync: false,
            needReadable: false,
            emittedReadable: false,
            readableListening: false,
            resumeScheduled: false,
            errorEmitted: false,
            emitClose: true,
            autoDestroy: true,
            destroyed: true,
            errored: null,
            closed: true,
            closeEmitted: true,
            defaultEncoding: 'utf8',
            awaitDrainWriters: null,
            multiAwaitDrain: false,
            readingMore: false,
            dataEmitted: true,
            decoder: null,
            encoding: null,
            [Symbol(kPaused)]: false
          },
          _events: [Object: null prototype] {
            error: [Function (anonymous)],
            data: [Function: bound ]
          },
          _eventsCount: 2,
          _maxListeners: undefined,
          emit: [Function (anonymous)],
          [Symbol(kFs)]: {
            appendFile: [Function: appendFile],
            appendFileSync: [Function: appendFileSync],
            access: [Function: access],
            accessSync: [Function: accessSync],
            chown: [Function: chown],
            chownSync: [Function: chownSync],
            chmod: [Function: chmod],
            chmodSync: [Function: chmodSync],
            close: [Function: close],
            closeSync: [Function: closeSync],
            copyFile: [Function: copyFile],
            copyFileSync: [Function: copyFileSync],
            cp: [Function: cp],
            cpSync: [Function: cpSync],
            createReadStream: [Function: createReadStream],
            createWriteStream: [Function: createWriteStream],
            exists: [Function: exists],
            existsSync: [Function: existsSync],
            fchown: [Function: fchown],
            fchownSync: [Function: fchownSync],
            fchmod: [Function: fchmod],
            fchmodSync: [Function: fchmodSync],
            fdatasync: [Function: fdatasync],
            fdatasyncSync: [Function: fdatasyncSync],
            fstat: [Function: fstat],
            fstatSync: [Function: fstatSync],
            fsync: [Function: fsync],
            fsyncSync: [Function: fsyncSync],
            ftruncate: [Function: ftruncate],
            ftruncateSync: [Function: ftruncateSync],
            futimes: [Function: futimes],
            futimesSync: [Function: futimesSync],
            lchown: [Function: lchown],
            lchownSync: [Function: lchownSync],
            lchmod: undefined,
            lchmodSync: undefined,
            link: [Function: link],
            linkSync: [Function: linkSync],
            lstat: [Function: lstat],
            lstatSync: [Function: lstatSync],
            lutimes: [Function: lutimes],
            lutimesSync: [Function: lutimesSync],
            mkdir: [Function: mkdir],
            mkdirSync: [Function: mkdirSync],
            mkdtemp: [Function: mkdtemp],
            mkdtempSync: [Function: mkdtempSync],
            open: [Function: open],
            openSync: [Function: openSync],
            opendir: [Function: opendir],
            opendirSync: [Function: opendirSync],
            readdir: [Function: readdir],
            readdirSync: [Function: readdirSync],
            read: [Function: read],
            readSync: [Function: readSync],
            readv: [Function: readv],
            readvSync: [Function: readvSync],
            readFile: [Function: readFile],
            readFileSync: [Function: readFileSync],
            readlink: [Function: readlink],
            readlinkSync: [Function: readlinkSync],
            realpath: [Function],
            realpathSync: [Function],
            rename: [Function: rename],
            renameSync: [Function: renameSync],
            rm: [Function: rm],
            rmSync: [Function: rmSync],
            rmdir: [Function: rmdir],
            rmdirSync: [Function: rmdirSync],
            stat: [Function: stat],
            statSync: [Function: statSync],
            symlink: [Function: symlink],
            symlinkSync: [Function: symlinkSync],
            truncate: [Function: truncate],
            truncateSync: [Function: truncateSync],
            unwatchFile: [Function: unwatchFile],
            unlink: [Function: unlink],
            unlinkSync: [Function: unlinkSync],
            utimes: [Function: utimes],
            utimesSync: [Function: utimesSync],
            watch: [Function: watch],
            watchFile: [Function: watchFile],
            writeFile: [Function: writeFile],
            writeFileSync: [Function: writeFileSync],
            write: [Function: write],
            writeSync: [Function: writeSync],
            writev: [Function: writev],
            writevSync: [Function: writevSync],
            Dir: [class Dir],
            Dirent: [class Dirent],
            Stats: [Function: Stats],
            ReadStream: [Getter/Setter],
            WriteStream: [Getter/Setter],
            FileReadStream: [Getter/Setter],
            FileWriteStream: [Getter/Setter],
            _toUnixTimestamp: [Function: toUnixTimestamp],
            F_OK: 0,
            R_OK: 4,
            W_OK: 2,
            X_OK: 1,
            constants: [Object: null prototype],
            promises: [Getter]
          },
          [Symbol(kIsPerformingIO)]: false,
          [Symbol(kCapture)]: false
        }
      }
    ]
  }
}

So uhhhhh maybe help me find the issue? Please? Or at least identify it and let me know what's wrong.

CodePudding user response:

Well it's telling you:

DiscordAPIError: Invalid Form Body
embeds[1].description: This field is required

You need to add an embed description field.

if (message.content == "-scp set avatar scare hamster"){
      let set = clients.user.setAvatar("./scare.jpg");
      let embed = new Discord.MessageEmbed()
      .setTitle("Successfully setted the bots avatar!")
      .setColor("GREEN")
      .setImage("attachment://scare.jpg")
      .setDescription("literally anything here")
      message.channel.send({embeds: [embed, set], files: [`./scare.jpg`]})
    }else

CodePudding user response:

Firstly, embed needs to have a description.

let embed = new Discord.MessageEmbed()
      .setTitle("Successfully setted the bots avatar!")
      .setDescription(`Set by ${message.author}`)
      .setColor("GREEN")
      .setImage("attachment://scare.jpg")

Secondly, set is not an embed. I don’t understand why you put it there. Change it to this:

message.channel.send({
  embeds: [
    embed
  ], 
  files: [
    `./scare.jpg`
  ]
})

I also advise you await the setting of the avatar (note this requires async callback)

await clients.user.setAvatar("./scare.jpg")
  • Related