Skip to content

Commit 683370f

Browse files
committed
Add -global option to deploy_commands
1 parent 0ef8aab commit 683370f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ Discord bot for MDN discord server.
33
Requires node v18+, run `npm install` to get required modules.
44

55
Run `node ./index.js` to start the application.
6-
If a slash command is added/removed or any command **data** is modified (i.e. name, description, parameters), then run `node ./deploy_commands.js` to sync this information with Discord.
6+
7+
If a slash command is added/removed or any command **data** is modified (i.e. name, description, parameters), then run `node ./deploy_commands.js` to sync this information with the development server on Discord. Use the `-global` flag to deploy these commands globally (to every Discord server the bot is in).
78

89
## Config File
910
The bot will need a *config.json* file in the root of the folder, in the following form:

deploy_commands.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ const { clientId, guildId, token } = require('./config.json');
33
const fs = require('node:fs');
44
const path = require('node:path');
55

6+
// Check if -global flag was used
7+
const global = process.argv[2] && process.argv[2] === '-global';
8+
69
const commands = [];
710
// Grab all the command folders from the commands directory
811
const foldersPath = path.join(__dirname, 'commands');
@@ -34,8 +37,8 @@ const rest = new REST().setToken(token);
3437

3538
// The put method is used to fully refresh all commands in the guild with the current set
3639
const data = await rest.put(
37-
Routes.applicationGuildCommands(clientId, guildId),
38-
// change above to Routes.applicationCommands(clientId) to make commands global
40+
// Deploy commands either to globally or to dev server
41+
global ? Routes.applicationCommands(clientId) : Routes.applicationGuildCommands(clientId, guildId),
3942
{ body: commands },
4043
);
4144

0 commit comments

Comments
 (0)