Stable joining with dummy commands sent on timeouts
This commit is contained in:
@@ -1,80 +0,0 @@
|
||||
import { REST, Routes } from 'discord.js';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
//const clientId = process.env.clientId;
|
||||
//const guildId = process.env.guildId;
|
||||
|
||||
const fs = require('node:fs');
|
||||
const path = require('node:path');
|
||||
|
||||
var commands = [];
|
||||
// Grab all the command files from the commands directory you created earlier
|
||||
const commandsPath = path.resolve(__dirname, '../commands');
|
||||
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
|
||||
|
||||
export function deploy (clientId, guildIDs) {
|
||||
console.log("Deploying commands for: ", guildIDs);
|
||||
if (!Array.isArray(guildIDs)) guildIDs = [guildIDs];
|
||||
// Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment
|
||||
for (const file of commandFiles) {
|
||||
const command = require(`${path.resolve(commandsPath, file)}`);
|
||||
console.log('Deploying Command: ', command);
|
||||
commands.push(command.data.toJSON());
|
||||
}
|
||||
|
||||
// Construct and prepare an instance of the REST module
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
||||
|
||||
// and deploy your commands!
|
||||
for (const guildId of guildIDs) {
|
||||
(async () => {
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands for guild ID: ${guildId}.`);
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
const data = await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands for guild ID: ${guildId}.`);
|
||||
} catch (error) {
|
||||
// And of course, make sure you catch and log any errors!
|
||||
console.log("ERROR Deploying commands: ", error, "Body from error: ", commands);
|
||||
}
|
||||
})()
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all commands for a given bot in a given guild
|
||||
*
|
||||
* @param {*} clientId The client ID of the bot to remove commands from
|
||||
* @param {*} guildId The ID of the guild to remove the bot commands from
|
||||
*/
|
||||
export function removeAll (clientId, guildId) {
|
||||
if (!Array.isArray(guildId)) guildIDs = [guildId];
|
||||
console.log("Removing commands for: ", clientId, guildIDs);
|
||||
|
||||
commands = [];
|
||||
|
||||
const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN);
|
||||
for (const guildId of guildIDs) {
|
||||
(async () => {
|
||||
try {
|
||||
console.log(`Started refreshing ${commands.length} application (/) commands for guild ID: ${guildId}.`);
|
||||
// The put method is used to fully refresh all commands in the guild with the current set
|
||||
const data = await rest.put(
|
||||
Routes.applicationGuildCommands(clientId, guildId),
|
||||
{ body: commands },
|
||||
);
|
||||
|
||||
console.log(`Successfully reloaded ${data.length} application (/) commands for guild ID: ${guildId}.`);
|
||||
} catch (error) {
|
||||
// And of course, make sure you catch and log any errors!
|
||||
console.log("ERROR Deploying commands: ", error, "Body from error: ", commands);
|
||||
}
|
||||
})()
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
import { Client, GatewayIntentBits } from 'discord.js';
|
||||
//import { deployActiveCommands } from '../discordBot/modules/deployCommands.mjs'
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
|
||||
@@ -28,10 +28,16 @@ nodeIo.on('connection', (socket) => {
|
||||
console.log('user disconnected');
|
||||
});
|
||||
|
||||
|
||||
// Test commands
|
||||
setTimeout(() => { sendNodeCommand(socket, "node-join", { 'some': 'data' }); }, 2500)
|
||||
setTimeout(() => { sendNodeCommand(socket, "node-leave", {}); }, 3500)
|
||||
setTimeout(() => {
|
||||
const joinData = {
|
||||
'clientID': "MTE5NjAwNTM2ODYzNjExMjk3Nw.GuCMXg.24iNNofNNumq46FIj68zMe9RmQgugAgfrvelEA",
|
||||
'channelID': "367396189529833476",
|
||||
'preset': ""
|
||||
}
|
||||
sendNodeCommand(socket, "node-join", joinData);
|
||||
}, 2500)
|
||||
//setTimeout(() => { sendNodeCommand(socket, "node-leave", {}); }, 3500)
|
||||
});
|
||||
|
||||
function sendNodeCommand(socket, command, data) {
|
||||
@@ -55,5 +61,4 @@ function updateNodeData(data) {
|
||||
|
||||
function nodeLoginWrapper(data) {
|
||||
console.log(`Login requested from node: ${data.id}`, data);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user