Restructure

This commit is contained in:
Wizzard 2024-02-05 19:18:42 -05:00
parent e851b7d169
commit bbf98e0a2a
5 changed files with 77 additions and 27 deletions

View File

@ -1 +1,2 @@
DISCORD_TOKEN=MAOISYHRO9 DISCORD_TOKEN=MAOISYHRO9
PREFIX=.

19
commands/delete.js Normal file
View File

@ -0,0 +1,19 @@
module.exports = {
name: 'delete',
description: 'Delete a specified number of your messages.',
async execute(message, args, deleteTimeout) {
const deleteCount = parseInt(args[0], 10);
if (isNaN(deleteCount)) {
const errorMsg = await message.channel.send('Please provide the number of messages to delete.');
setTimeout(() => errorMsg.delete().catch(console.error), deleteTimeout);
return;
}
const messages = await message.channel.messages.fetch({ limit: deleteCount + 1 });
const filtered = messages.filter(msg => msg.author.id === message.author.id);
filtered.forEach(msg => {
msg.delete().catch(console.error);
});
},
};

14
commands/help.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
name: 'help',
description: 'List all of my commands or info about a specific command.',
execute(message, args, deleteTimeout) {
let reply = 'Here are my supported commands:\n\n';
const commands = Array.from(message.client.commands.values());
reply += commands.map(command => `.${command.name} - ${command.description}`).join('\n');
message.channel.send(reply).then(sentMessage => {
setTimeout(() => sentMessage.delete().catch(console.error), deleteTimeout);
});
},
};

43
index.js Normal file
View File

@ -0,0 +1,43 @@
require('dotenv').config();
const { Client } = require('discord.js-selfbot-v13');
const client = new Client();
const fs = require('fs');
const PREFIX = process.env.PREFIX || '.';
const MESSAGE_DELETE_TIMEOUT = 10000
client.commands = new Map();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async message => {
if (message.author.id !== client.user.id || !message.content.startsWith(PREFIX)) return;
const args = message.content.slice(1).split(/ +/);
const commandName = args.shift().toLowerCase();
if (!client.commands.has(commandName)) return;
message.delete();
try {
await client.commands.get(commandName).execute(message, args, MESSAGE_DELETE_TIMEOUT);
} catch (error) {
console.error(error);
message.channel.send('There was an error trying to execute that command!')
.then(sentMessage => {
setTimeout(() => sentMessage.delete().catch(console.error), MESSAGE_DELETE_TIMEOUT);
});
}
});
client.login(process.env.DISCORD_TOKEN);

27
main.js
View File

@ -1,27 +0,0 @@
require('dotenv').config();
const { Client } = require('discord.js-selfbot-v13');
const client = new Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async message => {
if (message.author.id !== client.user.id) return;
if (message.content.startsWith('.delete')) {
const args = message.content.split(' ').slice(1);
const deleteCount = parseInt(args[0], 10);
if (!isNaN(deleteCount)) {
const messages = await message.channel.messages.fetch({ limit: deleteCount + 1 });
const filtered = messages.filter(msg => msg.author.id === client.user.id);
filtered.forEach(msg => msg.delete().catch(console.error));
}
} else if (message.content === '.help') {
message.channel.send('`.delete [number]` - Deletes a specified number of your messages.\n`.help` - Shows this help message.');
}
});
client.login(process.env.DISCORD_TOKEN);