The code imports dependencies from discord API and utilities, and defines a deleteCommands
function that retrieves a list of commands for a specified guild, skips exceptions, and deletes each command after a 3-second timeout. The deleteCommands
function is then exported as a module for use in other applications.
npm run import -- "delete all commands"
const {
registerCommand, getCommands, deleteCommand, updateCommand
} = importer.import("discord api")
const {timeout} = importer.import("discord utilities")
const EXCEPT_COMMANDS = [
]
async function deleteCommands(guildId) {
var toRemove = await getCommands(guildId)
for(var i = 0; i < toRemove.length; i++) {
if(EXCEPT_COMMANDS.includes(toRemove[i].name))
continue
await timeout(3000)
await deleteCommand(toRemove[i].id, guildId)
}
}
module.exports = deleteCommands
const { registerCommand, getCommands, deleteCommand, updateCommand } = require('discord.js').cmds;
const { timeout } = require('discord.js').utils;
/**
* Commands to be excluded from deletion
* @type {string[]}
*/
const EXCEPT_COMMANDS = [];
/**
* Deletes commands in a guild, excluding the ones specified in EXCEPT_COMMANDS
* @param {string} guildId - ID of the guild
*/
async function deleteCommands(guildId) {
// Get the commands in the guild
const commandsToDel = await getCommands(guildId);
// Filter out the commands that should be excluded
const commandsToDelFiltered = commandsToDel.filter((cmd) =>!EXCEPT_COMMANDS.includes(cmd.name));
// Wait for 3 seconds between each command deletion
for (const command of commandsToDelFiltered) {
await timeout(3000);
// Delete the command
await deleteCommand(command.id, guildId);
}
}
module.exports = deleteCommands;
The code imports the following dependencies:
registerCommand
, getCommands
, deleteCommand
, and updateCommand
from discord api
using importer.import('discord api')
.timeout
from discord utilities
using importer.import('discord utilities')
.EXCEPT_COMMANDS
is defined, but it remains empty.deleteCommands
is defined, which takes a guildId
parameter.The deleteCommands
function performs the following operations:
getCommands
to retrieve a list of commands for the specified guildId
.EXCEPT_COMMANDS
array. If it is, the function skips to the next iteration.timeout
.id
and guildId
using deleteCommand
.The deleteCommands
function is exported as a module using module.exports
.