client.on('interactionCreate', async (interaction)) { if (!interaction.inGuild()) return; if (!interaction.isCommand()) return; const commandnames = ['warn', 'mute', 'unmute', 'kick', 'ban', 'unban', 'forceban'] if (!commandnames.some(name => name === interaction.commandName)) return; const databasesetup = require('../databasesetup.js') const dbconnection = databasesetup.dbconnection const modlogdb = databasesetup.modlogdb(databaseconnect) const bansdb = databasesetup.bansdb(databaseconnect) if (!dbconnection) return await interaction.reply(erroremoji + ' Could not establish a connection to database, please contact Developers or higher.') await interaction.reply(loadingemoji + ' Verifying your request...') if (interaction.commandName === 'unban') { let targetid = interaction.options.getString('target'); try {await client.users.fetch(targetid)} catch {return await interaction.editReply(`${erroremoji} I could not find a user with the ID "${targetid}". That user probably doesn't exist.`)} let target = await client.users.fetch(targetid) let reason = interaction.options.getString('reason') if (!reason) reason = 'No reason was given' await interaction.editReply(loadingemoji + ' Processing...') const guild = await client.guilds.fetch(process.env.MAINSERVER_ID) await guild.bans.fetch(targetid) .catch(async (error) => { if (error.httpStatus == 404) { console.log('First time: \n\n' + error + '\n\n\n') return await interaction.editReply(`${erroremoji} That user is not banned.`) } else { console.error('Unexpected error when unbanning:\n' + error) return await interaction.editReply(`${erroremoji} An unexpected error occured when searching for the ban (Code ${error.httpStatus}). See the console for more details.`) } }) .then(async (output) => { return console.log('Second time\n\n' + output + '\n\n\n') }) // Here other stuff will be called for example modifying the database or actually unbanning the person, but not relevamt as I put both .catch and .then in a return (which actually returns). } }