using rest API to update server banner

I'm trying to use the REST api to update my server banner. The problem is that it seems to work - the await rest.patch() line does not throw an error, and it returns the guild object (which I believe it so be expected upon success). But when I look at my server, the banner is unchanged. I thought it might be cached, but I did a hard refresh on the website, and also waiting 12 hours. What am I doing wrong?
//import .env variables
import dotenv from 'dotenv';
dotenv.config();
import promises from 'fs/promises';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { glob } from 'glob';


const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {

//get guild data
let guild = await rest.get(Routes.guild(process.env.DISCORD_GUILD_ID));
console.log('Got guild "'+ guild.name +'"');
let guildHasBanner = guild.features.includes('BANNER');
console.log('Guild has banner: ', guildHasBanner, guild.banner);
if (!guildHasBanner) throw 'Guild does not have access to banner feature';

//get banner
let listOfBannerFiles = await glob('_banners/*.png');
let randomBannerFile = listOfBannerFiles[Math.floor(Math.random() * listOfBannerFiles.length)];
console.log('setting banner to: ', randomBannerFile);
let imageData = await loadImage(randomBannerFile);

//update banner
await rest.patch(Routes.guild(process.env.DISCORD_GUILD_ID), {data: {banner: imageData}});
console.log('Banner updated successfully!');
} catch (error) {
console.error(error);
}
})();
//import .env variables
import dotenv from 'dotenv';
dotenv.config();
import promises from 'fs/promises';
import { REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { glob } from 'glob';


const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);

(async () => {
try {

//get guild data
let guild = await rest.get(Routes.guild(process.env.DISCORD_GUILD_ID));
console.log('Got guild "'+ guild.name +'"');
let guildHasBanner = guild.features.includes('BANNER');
console.log('Guild has banner: ', guildHasBanner, guild.banner);
if (!guildHasBanner) throw 'Guild does not have access to banner feature';

//get banner
let listOfBannerFiles = await glob('_banners/*.png');
let randomBannerFile = listOfBannerFiles[Math.floor(Math.random() * listOfBannerFiles.length)];
console.log('setting banner to: ', randomBannerFile);
let imageData = await loadImage(randomBannerFile);

//update banner
await rest.patch(Routes.guild(process.env.DISCORD_GUILD_ID), {data: {banner: imageData}});
console.log('Banner updated successfully!');
} catch (error) {
console.error(error);
}
})();
2 Replies
d.js toolkit
d.js toolkit13mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
skeddles
skeddlesOP13mo ago
"@discordjs/rest": "^2.0.1", "discord-api-types": "^0.37.61", "discord.js": "^14.13.0", you need to use body, not data oh, thanks me, that was pretty obvious yeah, someone should have been able to see that easily
Want results from more Discord servers?
Add your server