dyLn
dyLn
DIAdiscord.js - Imagine an app
Created by dyLn on 3/8/2025 in #djs-questions
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}`);
}
}
}
2 replies
DIAdiscord.js - Imagine an app
Created by dyLn on 7/2/2024 in #djs-questions
Cannot read properties of undefined (reading 'reduce')
I have two apps and this error is happening on both when I try to run any interaction.
C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\BaseInteraction.js:106
this.entitlements = data.entitlements.reduce(
^

TypeError: Cannot read properties of undefined (reading 'reduce')
at new BaseInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\BaseInteraction.js:106:43)
at new CommandInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\CommandInteraction.js:16:5)
at new ChatInputCommandInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\ChatInputCommandInteraction.js:13:5)
at InteractionCreateAction.handle (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\actions\InteractionCreate.js:90:25)
at module.exports [as INTERACTION_CREATE] (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@discordjs\ws\dist\index.js:1190:51)
at WebSocketShard.emit (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)

Node.js v20.11.1
C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\BaseInteraction.js:106
this.entitlements = data.entitlements.reduce(
^

TypeError: Cannot read properties of undefined (reading 'reduce')
at new BaseInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\BaseInteraction.js:106:43)
at new CommandInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\CommandInteraction.js:16:5)
at new ChatInputCommandInteraction (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\structures\ChatInputCommandInteraction.js:13:5)
at InteractionCreateAction.handle (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\actions\InteractionCreate.js:90:25)
at module.exports [as INTERACTION_CREATE] (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\handlers\INTERACTION_CREATE.js:4:36)
at WebSocketManager.handlePacket (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\WebSocketManager.js:355:31)
at WebSocketManager.<anonymous> (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\discord.js\src\client\websocket\WebSocketManager.js:239:12)
at WebSocketManager.emit (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)
at WebSocketShard.<anonymous> (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@discordjs\ws\dist\index.js:1190:51)
at WebSocketShard.emit (C:\Users\the1a\Downloads\apps\dyLcore\node_modules\@vladfrangu\async_event_emitter\dist\index.cjs:282:31)

Node.js v20.11.1
5 replies
DIAdiscord.js - Imagine an app
Created by dyLn on 6/10/2024 in #djs-questions
ContextMenuCommandBuilder Permissions
I'm trying to add a User Command, and the permisisons through PermissionFlagsBits but I get an error. Here is the code snippet:
data: new ContextMenuCommandBuilder()
.setName("View User Avatar")
.setType(2)
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
data: new ContextMenuCommandBuilder()
.setName("View User Avatar")
.setType(2)
.setDMPermission(true)
.setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
And the error output:
Failed to update commands: Cannot read properties of undefined (reading 'ModerateMembers')
Failed to update commands: Cannot read properties of undefined (reading 'ModerateMembers')
discord.js v14.15.3 and node v20.11.1
7 replies