Search code examples
javascriptnode.jsapidiscordnode-fetch

Why am I getting a '400: Bad Request' when i try to change my Discord avatar?


Before i get 100 people telling me that automating user accounts is against the Terms of Service, I know that and i am willing to take the risk, i just came here for help because i've been trying for hours.

I checked how to change my profile picture on Discord's API Reference but when i tried, i got a '400: Bad Request' response. here is my code:

const fetch = require('node-fetch');
const fs = require('fs');
const tokens = fs.readFileSync('./tokens.txt', 'utf8').split('\n');

console.log('Changing profile pictures...');
let pfp = fs.readFileSync('./pfp.png', 'base64');
tokens.forEach(token => {
    fetch('https://discord.com/api/v8/users/@me', { method: 'PATCH', headers: { 'content-type': 'application/json', authorization: token.trim() }, body: { "avatar": `data:image/png;base64,${pfp}` } } )
    .then(res => res.json())
    .then(json => console.log(json));
});

I have checked and the tokens are correct when the request is send, so is the base64 encoded image, but i get a '400: bad request' response, so something must be wrong, but I unfortunately can't figure out what that thing is. If anyone could help i would appreciate it a lot


Solution

  • I just found out that i have to do JSON.stringify() for the body of the response.