// Modules const { SlashCommandBuilder } = require('discord.js'); const { DebugBuilder } = require("../utilities/debugBuilder"); const { getAllClientIds, getKeyByArrayValue, filterAutocompleteValues } = require("../utilities/utils"); const { getAllConnections } = require('../utilities/mysqlHandler'); const { leaveServerWrapper } = require('../controllers/adminController'); // Global Vars const log = new DebugBuilder("server", "leave"); module.exports = { data: new SlashCommandBuilder() .setName('leave') .setDescription('Disconnect a bot from the server') .addStringOption(option => option.setName("bot") .setDescription("The bot to disconnect from the server") .setAutocomplete(true) .setRequired(true)), example: "leave", isPrivileged: false, requiresTokens: false, defaultTokenUsage: 0, deferInitialReply: true, async autocomplete(interaction) { const connections = await getAllConnections(); const options = connections.map(conn => conn.clientObject.name); await filterAutocompleteValues(interaction, options); }, async execute(interaction) { try{ const botName = interaction.options.getString('bot'); log.DEBUG("Bot Name: ", botName) const clinetIds = await getAllClientIds(); log.DEBUG("Client names: ", clinetIds); const clientDiscordId = getKeyByArrayValue(clinetIds, {'name': botName}); log.DEBUG("Selected bot: ", clinetIds[clientDiscordId]); await leaveServerWrapper(clinetIds[clientDiscordId]); await interaction.editReply(`**${clinetIds[clientDiscordId].name}** has been disconnected`); // This will reply to the initial interaction //await interaction.channel.send('**word.**'); // This will send a message to the channel of the interaction outside of the initial reply }catch(err){ log.ERROR(err) //await interaction.reply(err.toString()); } } }