Change updateGuild to refresh guild and make it actually work

This commit is contained in:
powermaker450 2024-10-23 12:31:40 -04:00
parent c04b6ffc11
commit f5b18513d2
3 changed files with 19 additions and 9 deletions

View file

@ -6,7 +6,7 @@
"scripts": { "scripts": {
"build": "rm -rf ./dist && tsc -p .", "build": "rm -rf ./dist && tsc -p .",
"start": "node ./dist/main.js", "start": "node ./dist/main.js",
"refresh": "node ./dist/scripts/updateGuild.js", "refresh": "node ./dist/scripts/refreshGuild.js",
"prettier": "if prettier -v >/dev/null 2>&1; then prettier . --write; else npx prettier . --write; fi", "prettier": "if prettier -v >/dev/null 2>&1; then prettier . --write; else npx prettier . --write; fi",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },

View file

@ -29,7 +29,7 @@ const commandsData = Object.values(commands).map(command =>
command.data.toJSON() command.data.toJSON()
); );
const rest = new REST({ version: "9" }).setToken(BOT_TOKEN); export const rest = new REST({ version: "9" }).setToken(BOT_TOKEN);
export async function deployCommands({ guildId }: DeployCommandsProps) { export async function deployCommands({ guildId }: DeployCommandsProps) {
try { try {

View file

@ -16,22 +16,32 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
import { Events } from "discord.js"; import { Events, Routes } from "discord.js";
import { BotClient, deployCommands } from "../bot"; import { BOT_ID, BotClient, deployCommands, rest } from "../bot";
if (process.argv.length < 3 || !process.argv[2]) { if (process.argv.length < 3 || !process.argv[2]) {
console.log("You need to specify the guild ID to refresh."); console.log("You need to specify the guild ID to refresh.");
process.exit(1); process.exit(1);
} }
const [, , guildId] = process.argv;
BotClient.on(Events.ClientReady, () => { BotClient.on(Events.ClientReady, () => {
try { try {
BotClient.fetchGuildPreview(process.argv[2]) rest
.then(({ id, name }) => { .put(Routes.applicationGuildCommands(BOT_ID, guildId), { body: [] })
deployCommands({ guildId: id }); .then(() => {
console.log(`Updated (/) commands for "${name}".`); console.log("Deleted (/) commands.");
deployCommands({ guildId: guildId })
.then(() => {
console.log("Successfully reloaded (/) commands.");
process.exit(0); process.exit(0);
}) })
.catch(err => {
console.log("An error occurred refreshing (/) commands:", err);
process.exit(1);
});
})
.catch(err => { .catch(err => {
console.log("An error occured refreshing (/) commands:", err); console.log("An error occured refreshing (/) commands:", err);
process.exit(1); process.exit(1);