Home > Blockchain >  timeout.js discord.js v13 command not working
timeout.js discord.js v13 command not working

Time:04-11

I got this problem, when i wanna use a message embed in my timeout command, that i get a error message! I sended all of the command / files down there! i appreciate the help!

Here the Error Message:


TypeError: command.run is not a function
    at module.exports (/home/runner/Bolt-Utilities/events/guild/command.js:132:13)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Here the Timeout.js command:


const  MessageEmbed = require("discord.js");

module.exports = {
    name: 'timeout',
    aliases: ["tmute", "tm"],
    utilisation: '{prefix}timeout',

    async execute(client, message, args) {

      const fetch = require('node-fetch');
      const ms = require('ms');

      if (!message.member.permissions.has('TIMEOUT_MEMBERS')) {

        message.delete()
      
      } else {
      
        const user = message.mentions.users.first();

        const embed1 = new MessageEmbed()
          .setDescription("Please provide the user.")
          .setColor("RED");
      
        const embed2 = new MessageEmbed()
          .setDescription("Please specify the time.")
          .setColor("RED");

        const embed3 = new MessageEmbed()
          .setDescription("Please specify the time between **10 seconds** (10s) and **28 days** (28d).")
          .setColor("RED");

        if(!user) return message.reply({ embeds: [embed1] });

        const time = args.slice(1).join(' ');

        if(!time) return message.reply({ embeds: [embed2] });

        const milliseconds = ms(time);

        if(!milliseconds || milliseconds < 10000 || milliseconds > 2419200000) return message.reply({ embeds: [embed3] });

        const iosTime = new Date(Date.now()   milliseconds).toISOString();

            await fetch(`https://discord.com/api/guilds/${message.guild.id}/members/${user.id}`, {
                method: 'PATCH',
              body: JSON.stringify({ communication_disabled_until: iosTime }),
              headers: {
                    'Content-Type': 'application/json',
                    'Authorization': `Bot ${client.token}`,
                },
            });

        const embed4 = new MessageEmbed()
          .setDescription(`${user} has been **Timeout.** | \`${user.id}\``)
          .setColor("YELLOW");

        message.channel.send({ embeds: [embed4] })

      }
          
    },
};

and here the command.js file:


 if (!cooldowns.has(command.name)) {
    cooldowns.set(command.name, new Collection());
  }

  const now = Date.now();
  const timestamps = cooldowns.get(command.name);
  const cooldownAmount = (command.cooldown || 1) * 1000;

  if (timestamps.has(message.author.id)) {
    const expirationTime = timestamps.get(message.author.id)   cooldownAmount;

    if (now < expirationTime) {
      const timeLeft = (expirationTime - now) / 1000;
      return message.reply(
        `please wait ${timeLeft.toFixed(
          1
        )} more second(s) before reusing the \`${command.name}\` command.`
      );
    }
  }

  timestamps.set(message.author.id, now);
  setTimeout(() => timestamps.delete(message.author.id), cooldownAmount);

  try {
    command.run(client, message, args, p, cooldowns);
  } catch (error) {
    console.error(error);
    let embed2000 = new MessageEmbed()
      .setDescription("There was an error executing that command.")
      .setColor("BLUE");
    message.channel.send({ embeds: [embed2000] }).catch(console.error);
  }
};

That are all files! i hope someone can help me i dont know what is wrong there!

CodePudding user response:

Typo: you don't actually have a command.run function in your command file, instead you have execute. Change either one to be the same as the other will solve the problem.

Note: if you change the async execute to async run, change like the following:

 async run(client, message, args) => {
  • Related