-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(deploy): add deploy command as server-side function
remove the !deploy function (actually it is not available
- Loading branch information
Showing
3 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"token": "YOUR_TOKEN", | ||
"activityType": "PLAYING", | ||
"activity": "your music selections" | ||
"activity": "your music selections", | ||
"clientId": "YOUR_CLIENT_ID", | ||
"guildId": "YOUR_GUILD_ID,TARGET_SERVER_GUILD_ID", | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const { REST, Routes } = require('discord.js'); | ||
const { clientId, guildId, token } = require('../config.json'); | ||
const fs = require('node:fs'); | ||
|
||
const commands = []; | ||
// Grab all the command files from the commands directory you created earlier | ||
const commandFiles = fs.readdirSync('../commands') | ||
.filter(file => file.endsWith('.js')); | ||
|
||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment | ||
for (const file of commandFiles) { | ||
const command = require(`../commands/${file}`); | ||
commands.push(command.data.toJSON()); | ||
} | ||
console.log(commands); | ||
// log each option of each command | ||
for (const command of commands) { | ||
console.log(command.options); | ||
} | ||
// ask for the target before deploying | ||
console.log('Please enter the target (guild or global):'); | ||
const rl = require('readline').createInterface({ | ||
input: process.stdin, | ||
output: process.stdout, | ||
}); | ||
rl.on('line', (input) => { | ||
// Create a new REST instance | ||
const rest = new REST({ version: '10' }).setToken(token); | ||
|
||
(async () => { | ||
try { | ||
console.log('Started refreshing application (/) commands.'); | ||
|
||
if (input === 'global') { | ||
await rest.put( | ||
Routes.applicationCommands(clientId), | ||
{ body: commands }, | ||
); | ||
} | ||
// guild is the default, set the guild id in config.json | ||
else { | ||
await rest.put( | ||
Routes.applicationGuildCommands(clientId, guildId), | ||
{ body: commands }, | ||
); | ||
} | ||
|
||
console.log('Successfully reloaded application (/) commands.'); | ||
} | ||
catch (error) { | ||
console.error(error); | ||
} | ||
})(); | ||
rl.close(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters