how to sync the global command manually by myself

I have a main index.js file for my bot and I have a separate file for syncing the slash commands. Since I don't want to put the syncing code into main index.js file to let the bot sync every time while starting. But when I run the main index.js file and keeping it alive, I cannot execute any code which I could't run the syncing file to register my command. (if I ctrl+c, the bot will be terminated). Any idea of how this should be done or improved?
6 Replies
d.js toolkit
d.js toolkit16mo 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!
treble/luna
treble/luna16mo ago
run your deploy file first, then your bot you should only need to run it when you edit commands
master_30
master_30OP16mo ago
but when I did deployment code first, it shows: DiscordAPIError[20012]: You are not authorized to perform this action on this application
DiscordAPIError[20012]: You are not authorized to perform this action on this application
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async /home/timg233/bot_deployment/bamboo/src/util/deploy_global.js:39:18 {
requestBody: {
files: undefined,
json: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object]
]
},
rawError: {
message: 'You are not authorized to perform this action on this application',
code: 20012
},
code: 20012,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1110689306223312948/commands'
}
DiscordAPIError[20012]: You are not authorized to perform this action on this application
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async SequentialHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1021:23)
at async SequentialHandler.queueRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:862:14)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async /home/timg233/bot_deployment/bamboo/src/util/deploy_global.js:39:18 {
requestBody: {
files: undefined,
json: [
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object],
[Object], [Object], [Object]
]
},
rawError: {
message: 'You are not authorized to perform this action on this application',
code: 20012
},
code: 20012,
status: 403,
method: 'PUT',
url: 'https://discord.com/api/v10/applications/1110689306223312948/commands'
}
Squid
Squid16mo ago
that error means your client id is incorrect, your client token is incorrect, and/or the id and token do not belong to the same application the problem originates in the code for your deployment code
master_30
master_30OP16mo ago
Yes that's the problem, thx a lot. But after I tried, I found this error while using slash command ping, it is a really simple and fast command, but why it takes more than 3 second and return the error in the console
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:736:23)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async ChatInputCommandInteraction.reply (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/commands/ping.js:8:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/events/interaction_create.js:18:7) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1153052975716110458/aW50ZXJhY3Rpb246MTE1MzA1Mjk3NTcxNjExMDQ1ODpGTERuOEFNU05qVE1UejlVd0RZZ0ZnbVFpMTJnYkhIRXNkejBycEE5aWJxOGRLNTZmWHplOXRuUzJjM1dnV0J2eGdoeFZNcXcxdnZNSmdFejU4NldhczNRZVZmWGlub2RBeU92Uk81bFFFa3NxRTJacmJpbnExOFBiTmU5VjlKZA/callback'
}
Failed to reply to the interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:736:23)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async ChatInputCommandInteraction.reply (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/events/interaction_create.js:25:11) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1153052975716110458/aW50ZXJhY3Rpb246MTE1MzA1Mjk3NTcxNjExMDQ1ODpGTERuOEFNU05qVE1UejlVd0RZZ0ZnbVFpMTJnYkhIRXNkejBycEE5aWJxOGRLNTZmWHplOXRuUzJjM1dnV0J2eGdoeFZNcXcxdnZNSmdFejU4NldhczNRZVZmWGlub2RBeU92Uk81bFFFa3NxRTJacmJpbnExOFBiTmU5VjlKZA/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:736:23)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async ChatInputCommandInteraction.reply (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/commands/ping.js:8:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/events/interaction_create.js:18:7) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1153052975716110458/aW50ZXJhY3Rpb246MTE1MzA1Mjk3NTcxNjExMDQ1ODpGTERuOEFNU05qVE1UejlVd0RZZ0ZnbVFpMTJnYkhIRXNkejBycEE5aWJxOGRLNTZmWHplOXRuUzJjM1dnV0J2eGdoeFZNcXcxdnZNSmdFejU4NldhczNRZVZmWGlub2RBeU92Uk81bFFFa3NxRTJacmJpbnExOFBiTmU5VjlKZA/callback'
}
Failed to reply to the interaction: DiscordAPIError[10062]: Unknown interaction
at handleErrors (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:640:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async BurstHandler.runRequest (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:736:23)
at async REST.request (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/@[email protected]/node_modules/@discordjs/rest/dist/index.js:1387:22)
at async ChatInputCommandInteraction.reply (/home/timg233/bot_deployment/bamboo/node_modules/.pnpm/[email protected]/node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
at async Object.execute (/home/timg233/bot_deployment/bamboo/src/events/interaction_create.js:25:11) {
requestBody: { files: [], json: { type: 4, data: [Object] } },
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1153052975716110458/aW50ZXJhY3Rpb246MTE1MzA1Mjk3NTcxNjExMDQ1ODpGTERuOEFNU05qVE1UejlVd0RZZ0ZnbVFpMTJnYkhIRXNkejBycEE5aWJxOGRLNTZmWHplOXRuUzJjM1dnV0J2eGdoeFZNcXcxdnZNSmdFejU4NldhczNRZVZmWGlub2RBeU92Uk81bFFFa3NxRTJacmJpbnExOFBiTmU5VjlKZA/callback'
}
I host it locally on ubuntu (wsl). This should not be an internet problem. And I don't think I need to defer a ping command since it is fast
treble/luna
treble/luna16mo ago
it just indicates that your code takes over 3s to process, and is not related to djs
Want results from more Discord servers?
Add your server