djskage
Version:
A Discord.js extension for utility commands
43 lines (42 loc) • 1.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const mockInteraction_1 = require("../utils/mockInteraction");
module.exports = {
name: "repeat",
aliases: [],
description: "Repeat a command X amount of times",
usage: "repeat <command> <amount> <?d delay?> [args?...] (?c <#id> -> channel, ?u <@id> -> user)",
execute: async (djskage, client, message) => {
const args = message.content.split(" ").slice(2);
if (!args.length)
return;
const c = args.shift();
const dIdx = args.findIndex((a) => a === "?d");
const d = dIdx !== -1 ? args.splice(dIdx, 2)[1] : 500;
const guildCommands = await message.guild?.commands.fetch();
const globalCommands = await client.application?.commands.fetch();
const command = guildCommands?.find((cmd) => cmd.name === args[0]) ||
globalCommands?.find((cmd) => cmd.name === args[0]);
if (!command)
return message.reply(`Command "${args[0]}" not found.`);
const mockInteraction = new mockInteraction_1.Mockinteraction(client, message, command);
const delayArg = args.findIndex((arg) => arg.startsWith("?d"));
let delay = 500;
if (delayArg && delayArg !== -1) {
const delayInput = args[delayArg + 1];
if (delayInput && !isNaN(Number(delayInput))) {
delay = Number(delayInput);
}
args.splice(delayArg, 2);
}
message.reply(`Repeating command \`${mockInteraction.fullCommandName}\` \`${c}\` times with ${delay}ms delay.`);
const executeCommands = async (remaining) => {
if (remaining <= 0)
return;
client.emit("interactionCreate", mockInteraction);
setTimeout(() => executeCommands(remaining - 1), delay);
};
executeCommands(Number(c));
return;
},
};