title: How to make this function start via a slash command
body: <p>I have a piece of code that automatically runs every 4 hours to send a set message to a specific discord channel on my discord server but I would like to have this function start upon command and I would like that command to be in a separate file from my main index code if someone could give me a template for this code as a slash command I would greatly appreciate it you would be saving me days possibly weeks of tedious research and trial and error I need code that is up to date with v13 of discord.js and that will be compatible with my main index file code which will be set below the specific function that I want accomplished.</p>
  <pre><code>setInterval(() =&gt; {
      client.channels.cache.get(&quot;916642101989617684&quot;).send(&quot;!stats&quot;);
    }, (1000 * 60) * 240);
  
  
  const fs = require('fs');
  const { Client, Collection, Intents } = require('discord.js');
  const { token } = require('./config.json');
  
  const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
  
  client.commands = new Collection();
  const commandFiles = fs.readdirSync('./commands').filter(file =&gt; file.endsWith('.js'));
  
  for (const file of commandFiles) {
      const command = require(`./commands/${file}`);
      client.commands.set(command.data.name, command);
  }
  
  const eventFiles = fs.readdirSync('./events').filter(file =&gt; file.endsWith('.js'));
  
  for (const file of eventFiles) {
      const event = require(`./events/${file}`);
      if (event.once) {
          client.once(event.name, (...args) =&gt; event.execute(...args));
      } else {
          client.on(event.name, (...args) =&gt; event.execute(...args));
      }
  }
  
  client.once('ready', () =&gt; {
      console.log('Ready!');
  });
  
  setInterval(() =&gt; {
      client.channels.cache.get(&quot;916642101989617684&quot;).send(&quot;!stats&quot;);
    }, (1000 * 60) * 240);
     
    
  
  client.on('interactionCreate', async interaction =&gt; {
      if (!interaction.isCommand()) return;
  
      const command = client.commands.get(interaction.commandName);
  
      if (!command) return;
  
      try {
          await command.execute(interaction);
      } catch (error) {
          console.error(error);
          return interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
      }
  });
  
  client.login(token);
  </code></pre>