Skip to content

Commit

Permalink
fix(syncCommands): use process.exit() instead of close() in bot.ts
Browse files Browse the repository at this point in the history
Otherwise somehow close() gets executed, but can’t run because no db
exists.
  • Loading branch information
tippfehlr committed Apr 26, 2024
1 parent a834969 commit 2c71d82
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/modules/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Discord, { Events, GatewayIntentBits, Options } from 'discord.js';
import { getGuildConfig, roleRemoved } from './db';
import config from './config';
import { log } from './messages';
import { close } from '../index';
// import { close } from '../index';
import { initClientReady } from './bot.ready';
import { initPresenceUpdate } from './bot.presenceUpdate';

Expand Down Expand Up @@ -67,7 +67,7 @@ client.on(Events.Error, error => {
log.error(error, 'The Discord WebSocket has encountered an error');
stats.webSocketErrors++;
if (error.message === 'driver has already been destroyed') {
close();
process.exit();
}
});

Expand Down
6 changes: 2 additions & 4 deletions syncCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import path from 'path';
import { Command } from './src/modules/commandHandler';
import config from './src/modules/config';


const commandsDir = './src/modules/commands/';
const commands: RESTPostAPIApplicationCommandsJSONBody[] = [];
const commandFiles = fs.readdirSync(path.resolve(commandsDir)).filter(file => file.endsWith('.ts'));
Expand All @@ -14,19 +13,18 @@ for (const file of commandFiles) {
commands.push(command.data.toJSON());
}


const rest = new REST().setToken(config.TOKEN);

(async () => {
console.log(`Started refreshing ${commands.length} application (/) commands.`);
let data: any;
if (config.GUILD) {
data = await rest.put(Routes.applicationGuildCommands(config.APPLICATION_ID, config.GUILD), {
body: commands
body: commands,
});
} else {
data = await rest.put(Routes.applicationCommands(config.APPLICATION_ID), {
body: commands
body: commands,
});
}

Expand Down

0 comments on commit 2c71d82

Please sign in to comment.