diff --git a/EXAMPLE.env b/EXAMPLE.env index b2ed7ee..29c7493 100644 --- a/EXAMPLE.env +++ b/EXAMPLE.env @@ -1 +1,2 @@ DISCORD_TOKEN=MAOISYHRO9 +PREFIX=. diff --git a/commands/delete.js b/commands/delete.js new file mode 100644 index 0000000..e90504b --- /dev/null +++ b/commands/delete.js @@ -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); + }); + }, +}; diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..eefef7a --- /dev/null +++ b/commands/help.js @@ -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); + }); + }, +}; + diff --git a/index.js b/index.js new file mode 100644 index 0000000..b757526 --- /dev/null +++ b/index.js @@ -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); diff --git a/main.js b/main.js deleted file mode 100644 index d360e12..0000000 --- a/main.js +++ /dev/null @@ -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); -