Problem when trying to make a script that changes photos automatically (API)

Basically I’m trying to make a script that changes the photo on my website automatically when I change my discord profile picture, but for some reason it gives an error when trying to update the photo

const axios = require('axios');

const discordToken = 'TOKEN DISCORD';
const userId = 'ID';
const netlifyBuildHook = 'https://api.netlify.com/build_hooks/HOOK';
const netlifyApiEndpoint = 'https://api.netlify.com/api/v1';
const siteName = 'NAME';  

async function updateSiteImage() {
  try {
    const response = await axios.get(`https://discord.com/api/v10/users/${userId}`, {
      headers: {
        Authorization: `Bot ${discordToken}`,
      },
    });

    const avatarURL = response.data.avatar
      ? `https://cdn.discordapp.com/avatars/${userId}/${response.data.avatar}.jpg`
      : `https://cdn.discordapp.com/embed/avatars/${response.data.discriminator % 5}.png`;

    await updateNetlifyFile(avatarURL);
    await triggerNetlifyBuild();
  } catch (error) {
    console.error('Erro ao obter a imagem do Discord ou acionar o build do Netlify:', error.message);
  }
}

async function updateNetlifyFile(imageURL) {
  try {
    const netlifyAccessToken = 'TOKEN';
    const filePath = 'pfp.jpg'; 


    const deploysResponse = await axios.get(`${netlifyApiEndpoint}/sites/${siteName}/deploys?per_page=1`, {
      headers: {
        Authorization: `Bearer ${netlifyAccessToken}`,
      },
    });

    if (deploysResponse.data.length === 0) {
      console.error('Nenhum deploy encontrado.');
      return;
    }

    const latestDeploy = deploysResponse.data[0].id;

    await axios.post(`${netlifyApiEndpoint}/deploys/${latestDeploy}/restore`, {
      files: [
        {
          path: filePath,
          data: imageURL,
        },
      ],
    }, {
      headers: {
        Authorization: `Bearer ${netlifyAccessToken}`,
      },
    });

    console.log('Arquivo no Netlify atualizado com sucesso.');
  } catch (error) {
    console.error('Erro ao atualizar o arquivo no Netlify:', error.message);
  }
}

async function triggerNetlifyBuild() {
  try {
    await axios.post(netlifyBuildHook);
    console.log('Netlify build triggered successfully.');
  } catch (error) {
    console.error('Erro ao acionar o build do Netlify:', error.message);
  }
}

updateSiteImage();

Please explain how this is a Netlify issue as we do not intend to debug your code here. You can justify the post by:

  • Providing some info about the error that shows this is an error coming from Netlify and not your code
  • List some steps to reproduce the issue
  • Share some details about the site and your setup