Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
Command interaction not responding

this code is not executing the desired function which is to be able to initiate a message to repeat on a set interval. When debugging there are no errors and the bot comes online fine but the command can't be used and it says nothing to suggest what the problem is. I need a professionals help to identify the reason this code is not working and why the bot acts as if it does not even exist. This is the shortest amount of code to replicate the results I have left out the config.json because it has my token but I know for sure that that file is configured properly anyway

Test.ts file in commands folder

const Discord = require("discord.js");
const source = require('../index');
module.exports.run = (Client, message, args) => {
  if (!args [0]) return message.reply(`Please specify if you are turning the command on or off!`);
  if (args[1]) return message.reply(`Please specify if you are turning the command on or off! [Too many Arguments!]`);
  switch (args[0]) 
  {
    default:
    {
      message.reply('Invalid argument specified.')
      break;
    }
    case "on":
      {
        if (!source.timedCheck){
          source.timedCheck =setInterval(() =>{
            // Function for set interval
            console.log("Interval cycle run!" + (val++) + "times!");
            valcheck();
          }, 25 * 10000);
          message.reply('command started!');
        } else {
          return message.reply(`command already running!`)
        }
        break;
      }
    case "off":
      {
        if (source.timedCheck){
        message.reply(`user has turned off command!`);
        clearInterval(source.timedCheck);
        source.timedCheck = undefined;
        } else {
          return message.reply(`command already offline!`)
        }
        break;
      }  
  }

 let valcheck = () => {
   if (source.val > 5){
     clearInterval(source.timedCheck);
     source.timedCheck = undefined;
     message.channel.send(`command finished as scheduled!`);  
   } 
 };
};

module.exports.help = {
  name: "test",
  usage: "test <on/off>"
};

Index.js file

// Require the necessary discord.js classes
const { Client, Intents } = require('discord.js');
const { token } = require('./config.json');

// Create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });

// When the client is ready, run this code (only once)
client.once('ready', () => {
    console.log('Ready!');
});

// Export variables for commands
module.exports.timedCheck = undefined;
module.exports.val = 0;

// Login to Discord with your client's token
client.login(token);
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You didn't tell the bot to execute this command. In your Index file you have to require the command file, catch the "message" or the "interactionCreate" events and then execute your command. This code is incomplete and I can only guide you in a direction as you miss many things in your code.

You should read a tutorial: https://discordjs.guide/creating-your-bot/creating-commands.html#command-deployment-script

client.commands = new Discord.Collection();
const commandFiles = fs.readdirSync('./src/commands');

// require every command and add to commands collection
for (const file of commandFiles) {
  const command = require(`./src/commands/${file}`);
  client.commands.set(command.name, command);
}

client.on('message', async message => {

   // extract your args from the message, something like:
   const args = message.content.slice(prefix.length).split(/ +/);

   try {
      command.execute(message, args, client); // provide more vars if you need them
   } catch (error) {
      // handle errors here
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda