Skip to content

Commit

Permalink
Back to fix
Browse files Browse the repository at this point in the history
  • Loading branch information
schblondie committed Jan 23, 2023
1 parent 928b10d commit ef589d5
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions events/registerCommands.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ module.exports = {
if (v &&
typeof v === 'object' &&
!Object.keys(v).length ||
v === null ||
v === undefined ||
v.length === 0
v == null ||
v == undefined ||
v.length == 0
) {
if (Array.isArray(object))
object.splice(k, 1);
Expand Down Expand Up @@ -94,7 +94,7 @@ module.exports = {
// Create lists of global commands to add, update and delete
const globalAdd = []
const globalUpdate = []
const globalDelete = _.cloneDeep(globalCommands) //? This list starts with all global commands
const globalDelete = globalCommands.map(c => c)
// Loop through global commands
for (const command of globalCommandData) {
let commandJSON = command[1].data.toJSON()
Expand All @@ -118,12 +118,12 @@ module.exports = {
try {
// Check if command changed
if (_.isEqual(filteredC, filteredCommandJSON)) {
globalDelete.delete(globalCommand)
globalDelete.splice(globalDelete.indexOf(globalCommand), 1)
} else {
// Update command
await client.application.commands.edit(command[0], commandJSON)
await globalUpdate.push(commandJSON.name)
globalDelete.delete(globalCommand)
globalDelete.splice(globalDelete.indexOf(globalCommand), 1)
}
} catch {
// Add command
Expand Down Expand Up @@ -163,7 +163,7 @@ module.exports = {
// Create lists of commands to add, update and delete
const guildAdd = []
const guildUpdate = []
const guildDelete = _.cloneDeep(guildCommands)
const guildDelete = guildCommands.map((c) => c) //? This list starts with all guild commands
for (const command of commandData) {
let commandJSON = command[1].data.toJSON()
commandJSON = transformCommand(commandJSON)
Expand All @@ -186,15 +186,13 @@ module.exports = {
try {
// Check if command changed
if (_.isEqual(filteredC, filteredCommandJSON)) {
// Remove command from guildDelete object
guildDelete.delete(c)
// Delete command from guildDelete array
console.log(`Command ${commandJSON.name} in guild ${guild[1].id} is up to date`)
guildDelete.splice(guildDelete.indexOf(c), 1)
} else {
// Update command
await guild[1].commands.edit(c, commandJSON)
await guildUpdate.push(commandJSON.name)
guildDelete.delete(c)
guildDelete.splice(guildDelete.indexOf(c), 1)
}
} catch {
} catch (e) {
// Add command
guildAdd.push(commandJSON)
}
Expand All @@ -214,9 +212,9 @@ module.exports = {
}
// Delete guild commands which don't exist anymore
try {
// for (const command of guildDelete) {
// await guild[1].commands.delete(command[1])
// }
for (const command of guildDelete) {
await guild[1].commands.delete(command)
}
} catch (error) {
console.error(error)
}
Expand All @@ -226,4 +224,4 @@ module.exports = {
}
console.log('\x1b[32m%s\x1b[0m', 'Updated slash commands!')
}
}
}

0 comments on commit ef589d5

Please sign in to comment.