diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..aca6229 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,34 @@ +const fs = require('fs'); +const Discord = require('discord.js'); +const {prefix} = require('../config.json'); + + +module.exports = { + name: 'help', + description: 'List all available commands.', + execute(message) { + let str = ''; + const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); + + const embed = new Discord.MessageEmbed() + .setColor(15780145) + .setTitle("Help") + .setTimestamp() + .setAuthor("soilens bot", "https://cdn.discordapp.com/avatars/481128222147477506/1a30f57f8e403f54aaca502012aeff14.png?size=2048") + + + + for (const file of commandFiles) { + const command = require(`./${file}`); + str += `Name: ${command.name}, Description: ${command.description} \n`; + + + embed.addFields( + { name: prefix+command.name, value: command.description }, + ) + } + + message.channel.send(embed); + }, +}; + diff --git a/commands/say.js b/commands/say.js new file mode 100644 index 0000000..d2485da --- /dev/null +++ b/commands/say.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'say', + description: 'Repeats arguments', + execute(message, args) { + message.channel.send(args.join(" ")) + } +}; \ No newline at end of file diff --git a/server.js b/server.js new file mode 100644 index 0000000..94dd4bf --- /dev/null +++ b/server.js @@ -0,0 +1,56 @@ +const fs = require('fs') +const Discord = require('discord.js'); +const client = new Discord.Client({ disableEveryone: true }); +const { + prefix, + token, +} = require('./config.json'); + +client.commands = new Discord.Collection(); + +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); +} + +console.log(client.commands); + +client.once('ready', () => { + console.log('Ready!'); +}); + +client.once('reconnecting', () => { + console.log('Reconnecting!'); +}); + +client.once('disconnect', () => { + console.log('Disconnect!'); +}); + +client.on('message', async message => { + const args = message.content.slice(prefix.length).split(" ") + const commandName = args.shift().toLowerCase(); + const command = client.commands.get(commandName); + + if (message.author.bot) return; + if (!message.content.startsWith(prefix)) return; + + try { + if (commandName == "ban" || commandName == "userinfo") { + command.execute(message, client); + } else if (commandName == "say") { + command.execute(message, args.join(" ")) + } + else { + command.execute(message); + } + } catch (error) { + console.error(error); + message.reply('There was an error trying to execute that command!'); + } +}); + + +client.login(token); \ No newline at end of file