conversion of ApplicationCommand to SlashCommandBuilder object

is there a way to convert ApplicationCommand to SlashCommandBuilder object? coz the object received from fetching the API and the locally created ones won't match when I directly compare them after serialization
28 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
xubby
xubbyOP2y ago
For example converting this:
ApplicationCommand {
id: '1112489448605761541',
applicationId: '1096844434202697728',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1112489448605761541'
},
type: 1,
nsfw: false,
name: 'rename',
nameLocalizations: null,
nameLocalized: null,
description: 'Mass renaming of channels',
descriptionLocalizations: null,
descriptionLocalized: null,
options: [ [Object], [Object] ],
defaultMemberPermissions: PermissionsBitField { bitfield: 16n },
dmPermission: false,
version: '1112489448605761542'
}
ApplicationCommand {
id: '1112489448605761541',
applicationId: '1096844434202697728',
guild: null,
guildId: null,
permissions: ApplicationCommandPermissionsManager {
manager: [Circular *1],
guild: null,
guildId: null,
commandId: '1112489448605761541'
},
type: 1,
nsfw: false,
name: 'rename',
nameLocalizations: null,
nameLocalized: null,
description: 'Mass renaming of channels',
descriptionLocalizations: null,
descriptionLocalized: null,
options: [ [Object], [Object] ],
defaultMemberPermissions: PermissionsBitField { bitfield: 16n },
dmPermission: false,
version: '1112489448605761542'
}
to this:
SlashCommandBuilder {
options: [Array],
name: 'rename',
name_localizations: undefined,
description: 'Mass renaming of channels',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: '16',
dm_permission: false,
nsfw: undefined
}
SlashCommandBuilder {
options: [Array],
name: 'rename',
name_localizations: undefined,
description: 'Mass renaming of channels',
description_localizations: undefined,
default_permission: undefined,
default_member_permissions: '16',
dm_permission: false,
nsfw: undefined
}
also don't mind the command action 😅 they are renamed in non-spammy intervals
sexy dark chocolate
Use the slashcommandbuilder On the applicationcommand
xubby
xubbyOP2y ago
how if the scb constructor doesn't take arguments?
MrMythical
MrMythical2y ago
What exactly is your use case?
xubby
xubbyOP2y ago
check system to decide whether to deploy all/new local commands if the commands fetch from the API don't match the local ones
sexy dark chocolate
Well, use the methods You don't have to do it for each an every application command, you can use a map
xubby
xubbyOP2y ago
💀 if I use the methods, it would be another adventure in rewrite my own slash command builder so stressful
sexy dark chocolate
I thought it was to like, viewthe application command object as a slashcommandbuilder object Maybe if I understand thr goal I'd know what to do
xubby
xubbyOP2y ago
I mean even if I do so, how would I access the properties. I'm actually stuck on a way to access properties with the same name easily like: dmPermission and dm_permission I would have gone with iterating them with a for..in loop but I really doubt the ordering in the object so my only option is to access them by their names
sexy dark chocolate
I thought that's what the slash command builder was for, to make all the objects alike and compare, comparing names may be easier though since slash command names are unique
xubby
xubbyOP2y ago
I'm trying to compare the whole object and see if there's any difference, in relation to the other if I serialize it and compare, it will always be false coz the API data contains more properties than the builder object does not to forget the differences in values and names of properties
sexy dark chocolate
Oh then, try converting the builder to json That should give an applicationcommand object
xubby
xubbyOP2y ago
nah.. it's the same I wish the slash command builder used the same property names as the API does djsGame
sexy dark chocolate
It does, the ApplicationCommand object discord.js returns has its properties in pascalCase Thats the one you are getting I'm not sure how you'd convert a slashcommandbuilder object to that though
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
xubby
xubbyOP2y ago
it's the opposite, I want the ApplicationCommand -> SlashCommandBuilder object it's weird that APIApplicationCommand is the same as builder object tho 🤔
sexy dark chocolate
The slash command builder is what you use to deploy commands, the applicationcommand object is from like, fetching commands or getting commands from the cache
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
xubby
xubbyOP2y ago
ya but like having the same property names would be easier coz the only work left would be matching mutual properties in both objects
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
sexy dark chocolate
Yeah that's why it has the same properties as the apiapplicationcommand object But you said you wanna convert the application command object to a slashcommandbuilder object, why doesn't the builder work for you again?
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
xubby
xubbyOP2y ago
because I'll have to manually pass each property and who knows how many transformations I'd have to do to each property FeelsBadMan I guess it's time to move to raw json
sexy dark chocolate
It is alot of work but I can't think of another way, since the builder doesn't provide a method for this nor can you use the constructor so
xubby
xubbyOP2y ago
ikr! :pepehands:
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
xubby
xubbyOP2y ago
ohh FeelsBadMan
Want results from more Discord servers?
Add your server