Error using User Apps in my bot

I get this error while using a user application cmds
2025-04-21 14:37:53 - ERROR - Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "::virtual::" DiscordAPIError[50001]: Missing Access
2025-04-21 14:37:53 - ERROR - at handleErrors (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\Shared.ts:148:10)
2025-04-21 14:37:53 - ERROR - at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
2025-04-21 14:37:53 - ERROR - at async SequentialHandler.runRequest (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\SequentialHandler.ts:417:20)
2025-04-21 14:37:53 - ERROR - at async SequentialHandler.queueRequest (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\SequentialHandler.ts:169:11)
2025-04-21 14:37:53 - ERROR - at async _REST.request (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\REST.ts:210:20)
2025-04-21 14:37:53 - ERROR - at async ChannelManager.fetch (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\discord.js@14.18.0\node_modules\discord.js\src\managers\ChannelManager.js:123:18)
2025-04-21 14:37:53 - ERROR - Encountered error on event listener "CorePreChatInputCommandRun" for event "preChatInputCommandRun" at path "::virtual::" DiscordAPIError[50001]: Missing Access
2025-04-21 14:37:53 - ERROR - at handleErrors (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\Shared.ts:148:10)
2025-04-21 14:37:53 - ERROR - at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
2025-04-21 14:37:53 - ERROR - at async SequentialHandler.runRequest (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\SequentialHandler.ts:417:20)
2025-04-21 14:37:53 - ERROR - at async SequentialHandler.queueRequest (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\handlers\SequentialHandler.ts:169:11)
2025-04-21 14:37:53 - ERROR - at async _REST.request (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@discordjs+rest@2.4.3\node_modules\@discordjs\rest\src\lib\REST.ts:210:20)
2025-04-21 14:37:53 - ERROR - at async ChannelManager.fetch (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\discord.js@14.18.0\node_modules\discord.js\src\managers\ChannelManager.js:123:18)
20 Replies
Tejas
TejasOP2w ago
Rest of the error
2025-04-21 14:37:53 - ERROR - at async _CorePrecondition.fetchChannelFromInteraction (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\lib\structures\Precondition.ts:52:20)
2025-04-21 14:37:53 - ERROR - at async _CorePrecondition.chatInputRun (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\preconditions\RunIn.ts:34:24)
2025-04-21 14:37:53 - ERROR - at async Object.chatInputSequential (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\lib\utils\preconditions\conditions\PreconditionConditionAnd.ts:25:19)
2025-04-21 14:37:53 - ERROR - at async _CoreListener.run (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\listeners\application-commands\chat-input\CorePreChatInputCommandRun.ts:21:23) {
2025-04-21 14:37:53 - ERROR - requestBody: [Object],
2025-04-21 14:37:53 - ERROR - rawError: [Object],
2025-04-21 14:37:53 - ERROR - code: 50001,
2025-04-21 14:37:53 - ERROR - status: 403,
2025-04-21 14:37:53 - ERROR - method: 'GET',
2025-04-21 14:37:53 - ERROR - url: 'https://discord.com/api/v10/channels/831168306634686474'
2025-04-21 14:37:53 - ERROR - }
2025-04-21 14:37:53 - ERROR - at async _CorePrecondition.fetchChannelFromInteraction (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\lib\structures\Precondition.ts:52:20)
2025-04-21 14:37:53 - ERROR - at async _CorePrecondition.chatInputRun (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\preconditions\RunIn.ts:34:24)
2025-04-21 14:37:53 - ERROR - at async Object.chatInputSequential (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\lib\utils\preconditions\conditions\PreconditionConditionAnd.ts:25:19)
2025-04-21 14:37:53 - ERROR - at async _CoreListener.run (C:\Users\Tejas\Desktop\Source-Codes\Bots\rudescore\rudescore-rewrite\node_modules\.pnpm\@sapphire+framework@5.3.4\node_modules\@sapphire\framework\src\listeners\application-commands\chat-input\CorePreChatInputCommandRun.ts:21:23) {
2025-04-21 14:37:53 - ERROR - requestBody: [Object],
2025-04-21 14:37:53 - ERROR - rawError: [Object],
2025-04-21 14:37:53 - ERROR - code: 50001,
2025-04-21 14:37:53 - ERROR - status: 403,
2025-04-21 14:37:53 - ERROR - method: 'GET',
2025-04-21 14:37:53 - ERROR - url: 'https://discord.com/api/v10/channels/831168306634686474'
2025-04-21 14:37:53 - ERROR - }
Favna
Favna2w ago
RunIn precondition is failing because of missing permissions. Your bot probably doesn't have the correct intents or the VIEW_CHANNEL permission
Tejas
TejasOP2w ago
But it's a user application cmd how does perms in that server effect it?
Favna
Favna2w ago
what is the RunIn you provided on the command I mean you must have added it to the options. It's not automatic.
Tejas
TejasOP2w ago
It's
runIn: [CommandOptionsRunTypeEnum.GuildAny, CommandOptionsRunTypeEnum.Dm],
runIn: [CommandOptionsRunTypeEnum.GuildAny, CommandOptionsRunTypeEnum.Dm],
Favna
Favna2w ago
I mean at that point you can just remove it ... that covers everything
Tejas
TejasOP2w ago
I thought it would be considered a DM channel in user apps :/ so the cmd would execute
Favna
Favna2w ago
nah DM channel is when you DM the bot user apps are completely separate
Tejas
TejasOP2w ago
so why are these checks running on user apps then, shouln't they be an exception?
Favna
Favna2w ago
ehm... why.. because the code is from before user apps were a thing and it wasn't implemented. Should they be running at all.. idk, that's a design choice we havent made yet. Truth be told not a lot of development for sapphire has happened over the past many months. I can say the reason for that is lack of time and yeah sure it plays a part, but it's also lack of motivation from Vladdy, Kyra and myself. We all have full time software engineering jobs and maintaining an open source project next to that in our free time that pays nothing back isn't really motivation boosting.
Tejas
TejasOP2w ago
Fair enough, also I was looking at Using the built in OAUTH2 route (backend) and I was messing around and was wondering if I have something like the ss below, we can't overwrite the existing route?
Sapphire Framework
Using the built in OAUTH2 route (backend) | Sapphire
If you are using localhost as your test environment, make sure you use http//localhost in
No description
Tejas
TejasOP2w ago
Specifically this
No description
Favna
Favna2w ago
no but why would you want to? the route ultimately really doesn't matter because you call it from your frontend and what route you call is arbitrary
Tejas
TejasOP2w ago
That is true I can change the route, I just wanted this token and store it somewhere in the backend, is this possible with the default setup?
No description
Favna
Favna2w ago
it is not, nor should you. That's not how cookie authentication works. As shown right there, we dont use JWT tokens in the traditional sense. The backend sets the cookie and on the frontend you include credentials: true in your request options and the authentication is automagically shared
Favna
Favna2w ago
Fireship
YouTube
Session vs Token Authentication in 100 Seconds
Learn the difference between session and token-based authentication on the web. Master Web Security in 12 weeks 👉 https://websecurity-academy.com/?aff=487495_h0fjhwrd Enroll before the deadline on 31st Oct (Saturday). #web #security #100SecondsOfCode
Tejas
TejasOP2w ago
Let's say I have a simple route like this
@ApplyOptions<Route.Options>({ route: "guild/:guildId/delete-settings" })
export class DeleteSettingsRoute extends Route {
async run(request: ApiRequest, response: ApiResponse) {
const { guildId } = request.params;
const { userId, token } = request.query;

if (!userId || !token) {
return response.status(401).json({ error: "Unauthorized" });
}

const isAdmin = await checkIfGuildAdmin(guildId, userId, token);
if (!isAdmin) {
return response.status(403).json({ error: "Forbidden" });
}

return response.json({ success: true });
}
}
@ApplyOptions<Route.Options>({ route: "guild/:guildId/delete-settings" })
export class DeleteSettingsRoute extends Route {
async run(request: ApiRequest, response: ApiResponse) {
const { guildId } = request.params;
const { userId, token } = request.query;

if (!userId || !token) {
return response.status(401).json({ error: "Unauthorized" });
}

const isAdmin = await checkIfGuildAdmin(guildId, userId, token);
if (!isAdmin) {
return response.status(403).json({ error: "Forbidden" });
}

return response.json({ success: true });
}
}
In this ex, I'm relying on userId and token being passed in manually to verify access. but with the session based approach you're talking abt (cookie + credentials: true), how should I identify and authorize the user server side if I'm not storing anything backend-side or decoding a JWT? In other words how do I securely know who the user is in a route handler if all the state is in a cookie and I'm not querying or validating it explicitly?
Favna
Favna2w ago
did you check out this guide page? https://www.sapphirejs.dev/docs/Guide/plugins/API/authenticating-routes Other than that you can get the discordjs User object through this.container.client.users.fetch(request.auth!.id) and then do with it as you please
Sapphire Framework
Locking routes behind authentication | Sapphire
When writing an API that is publicly available for consumption, it is often desirable to lock some routes behind them
Tejas
TejasOP2w ago
oh my bad I stopped reading the docs on data transformers and kept wondering about this

Did you find this page helpful?