Skip to content

Commit 818045b

Browse files
committed
new approach: only use a put for all cmds
1 parent f7098aa commit 818045b

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

README.md

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,14 @@ client.login(process.env.DISCORD_TOKEN);
9595

9696
### Delete a guild-command
9797

98-
The name of a command of an application is unique, but only in its type.
99-
Make sure that **you** have command's id and not it's name.
98+
Global commands can be automatically deleted if you just delete the file or set `ignore: true` and run the `deployCommands` function again.
99+
100+
Guild commands on the other hand need to be deleted manually.
101+
102+
The name of a command of an application is unique, but only in its type. Command ids are unique.
103+
Make sure that you have command's id and not it's name.
104+
105+
You can get the command id by either typing in the command and then right click the description above or by giong into the guild settings > Integrations > YOUR_BOT > right mouse click on the command > **Copy Command ID**
100106

101107
In this example we are building a manager-command that has StringOptions for the command and the guild id where one can paste in the ID or the name.
102108

@@ -105,21 +111,21 @@ const { SlashCommandBuilder, EmbedBuilder } = require("discord.js");
105111
const { deleteCommand } = require("djs-command-helper");
106112

107113
module.exports = {
108-
guildIds: ["1114825999155200101"],
114+
guildIds: ["12345"], // the guild id of the dev's guild so that no one can delete every command
109115
data: new SlashCommandBuilder()
110116
.setName("manage-commands")
111117
.setDescription("Replies with Pong!")
112118
.addStringOption((op) =>
113119
op
114120
.setName("command-id")
115-
.setDescription(
116-
"The ID of the command to be removed"
117-
)
121+
.setDescription("The ID of the command to be removed")
118122
)
119123
.addStringOption((op) =>
120124
op
121125
.setName("server-id")
122-
.setDescription("The ID of the server from which the command is to be removed")
126+
.setDescription(
127+
"The ID of the server from which the command is to be removed"
128+
)
123129
),
124130

125131
// This function is called whenever an interactionCreate event is triggered.
@@ -128,20 +134,20 @@ module.exports = {
128134
const command = interaction.options.getString("command-id");
129135
await interaction.deferReply({ ephemeral: true }); // Defer to remove the risk of not responding in time
130136

131-
132137
try {
133138
const response = await deleteCommand(command, {
134139
appToken: interaction.client.token,
135140
appId: interaction.application.id,
136141
guildId: guildId,
137142
});
138-
} catch (err) { // respond with an error if the operation fails in some way
143+
} catch (err) {
144+
// respond with an error if the operation fails in some way
139145
return await interaction.editReply({
140146
embeds: [
141147
new EmbedBuilder()
142148
.setTitle("❌ Command not deleted due to an error")
143149
.setDescription("```" + err + "```")
144-
.setColor(0xee0000),
150+
.setColor(0xff0000),
145151
],
146152
});
147153
}

index.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const { REST } = require("@discordjs/rest");
1+
const REST = require("@discordjs/rest");
22
const { readdirSync } = require("node:fs");
33
const path = require("node:path");
44

@@ -10,10 +10,10 @@ const Routes = {
1010
return `/applications/${appId}/commands/${cmdId}`;
1111
},
1212
guildCommands: (appId, guildId) => {
13-
return `/applications/${appId}/commands/guilds/${guildId}/commands`;
13+
return `/applications/${appId}/guilds/${guildId}/commands`;
1414
},
1515
guildCommand: (appId, guildId, cmdId) => {
16-
return `/applications/${appId}/commands/guilds/${guildId}/commands/${cmdId}`;
16+
return `/applications/${appId}/guilds/${guildId}/commands/${cmdId}`;
1717
},
1818
};
1919

@@ -67,12 +67,6 @@ module.exports.deployCommands = async function deployCommands(
6767
try {
6868
const rest = new REST().setToken(opts.appToken);
6969

70-
const currentCommands = await rest.get(Routes.commands(clientId));
71-
let currentMap = new Map();
72-
currentCommands.forEach((cmd) => {
73-
currentMap.set(cmd.name, cmd);
74-
});
75-
7670
for (const file of commandFiles) {
7771
const filePath = path.join(folderPath, file);
7872
const command = require(filePath);
@@ -87,7 +81,7 @@ module.exports.deployCommands = async function deployCommands(
8781
continue;
8882
}
8983

90-
if ((command.guildIds ?? []).length > 0) {
84+
if ((command.guildIds || []).length > 0) {
9185
privateCommands.push({
9286
data: command.data,
9387
guildIds: command.guildIds,

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "djs-command-helper",
3-
"version": "2.0.4",
3+
"version": "3.0.0",
44
"description": "A simple, easy to use module that houses functions to can refresh global and guild specific commands for your Discord App.",
55
"main": "./index.js",
6-
"scripts": { },
6+
"scripts": {},
77
"keywords": [
88
"discord",
99
"discord.js",
@@ -17,7 +17,7 @@
1717
"license": "MIT",
1818
"repository": {
1919
"type": "git",
20-
"url": "https://github.com/The-LukeZ/djsCommandDeployer.git"
20+
"url": "https://github.com/The-LukeZ/djsCommandHelper.git"
2121
},
2222
"registry": "https://npm.pkg.github.com",
2323
"dependencies": {

0 commit comments

Comments
 (0)