405 Method Not Allowed

Getting this error when trying to upload new emojis.
5:08:22 AM Failed to upload emoji "i_user": DiscordAPIError[0]: 405: Method Not Allowed
at handleErrors (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:686:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async SequentialHandler.runRequest (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:1087:23)
at async SequentialHandler.queueRequest (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:918:14)
at async _REST.request (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:1231:22)
at async uploadMissingEmojis (file:///C:/Users/the1a/Downloads/apps/dyLcore/src/handlers/emojiHandler.js:64:30)
5:08:22 AM Failed to upload emoji "i_user": DiscordAPIError[0]: 405: Method Not Allowed
at handleErrors (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:686:13)
at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
at async SequentialHandler.runRequest (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:1087:23)
at async SequentialHandler.queueRequest (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:918:14)
at async _REST.request (file:///C:/Users/the1a/Downloads/apps/dyLcore/node_modules/@discordjs/rest/dist/index.mjs:1231:22)
at async uploadMissingEmojis (file:///C:/Users/the1a/Downloads/apps/dyLcore/src/handlers/emojiHandler.js:64:30)
export async function uploadMissingEmojis(client) {
let emojiFiles = [];

try {
emojiFiles = fs
.readdirSync(emojiDir)
.filter(file => file.endsWith('.png'));

if (emojiFiles.length > 0) {
log(`Detected ${emojiFiles.length} emoji files to upload.`);
}
} catch (e) {
error(`Failed to read emoji directory: ${e}`);
return;
}

const rest = new REST({ version: '10' }).setToken(client.token);

let appEmojis = [];

try {
appEmojis = await rest.get(Routes.applicationEmojis(client.application.id), {
headers: { Authorization: `Bot ${client.token}` }
});
} catch (e) {
warn(`Unable to fetch application emojis. Continuing without duplicate check: ${e}`);
}

if (!Array.isArray(appEmojis)) {
appEmojis = Object.values(appEmojis);
}

for (const file of emojiFiles) {
const emojiName = path.basename(file, path.extname(file));

if (appEmojis.some(e => e.name === emojiName)) {
debug(`Emoji "${emojiName}" already exists in the bot's application emojis.`);
continue;
}

const emojiPath = path.join(emojiDir, file);
let emojiBuffer;
try {
emojiBuffer = fs.readFileSync(emojiPath);
} catch (e) {
error(`Failed to read emoji file "${file}": ${e}`);
continue;
}
const imageData = `data:image/png;base64,${emojiBuffer.toString('base64')}`;

try {
const newEmoji = await rest.post(
Routes.applicationEmoji(client.application.id),
{
body: { name: emojiName, image: imageData },
}
);
success(`Uploaded emoji "${newEmoji.name}" to the bot's application.`);
} catch (e) {
error(`Failed to upload emoji "${emojiName}": ${e.stack}`);
}
}
}
export async function uploadMissingEmojis(client) {
let emojiFiles = [];

try {
emojiFiles = fs
.readdirSync(emojiDir)
.filter(file => file.endsWith('.png'));

if (emojiFiles.length > 0) {
log(`Detected ${emojiFiles.length} emoji files to upload.`);
}
} catch (e) {
error(`Failed to read emoji directory: ${e}`);
return;
}

const rest = new REST({ version: '10' }).setToken(client.token);

let appEmojis = [];

try {
appEmojis = await rest.get(Routes.applicationEmojis(client.application.id), {
headers: { Authorization: `Bot ${client.token}` }
});
} catch (e) {
warn(`Unable to fetch application emojis. Continuing without duplicate check: ${e}`);
}

if (!Array.isArray(appEmojis)) {
appEmojis = Object.values(appEmojis);
}

for (const file of emojiFiles) {
const emojiName = path.basename(file, path.extname(file));

if (appEmojis.some(e => e.name === emojiName)) {
debug(`Emoji "${emojiName}" already exists in the bot's application emojis.`);
continue;
}

const emojiPath = path.join(emojiDir, file);
let emojiBuffer;
try {
emojiBuffer = fs.readFileSync(emojiPath);
} catch (e) {
error(`Failed to read emoji file "${file}": ${e}`);
continue;
}
const imageData = `data:image/png;base64,${emojiBuffer.toString('base64')}`;

try {
const newEmoji = await rest.post(
Routes.applicationEmoji(client.application.id),
{
body: { name: emojiName, image: imageData },
}
);
success(`Uploaded emoji "${newEmoji.name}" to the bot's application.`);
} catch (e) {
error(`Failed to upload emoji "${emojiName}": ${e.stack}`);
}
}
}
1 Reply
d.js toolkit
d.js toolkit2mo 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

Did you find this page helpful?