이세린

Edited Command Hanlder, Using Run instead of Execute, Cute Command now complete

1 +const Discord = require('discord.js');
2 +
1 module.exports = { 3 module.exports = {
2 name: 'breathe', 4 name: 'breathe',
3 description: 'Embeds a gif', 5 description: 'Embeds a gif',
......
1 +const Discord = require('discord.js');
2 +
1 module.exports = { 3 module.exports = {
2 name: 'calm', 4 name: 'calm',
3 description: 'Actual help section', 5 description: 'Actual help section',
4 - execute(message, args, Discord){ 6 + async run(client, message, args){
5 - const calmEmbed = new Discord.MessageEmbed() 7 + const calm = new Discord.MessageEmbed()
6 .setColor('#91B2C7') 8 .setColor('#91B2C7')
7 .setDescription("It's okay, I'm here to help! What would you like to do?") 9 .setDescription("It's okay, I'm here to help! What would you like to do?")
8 .addFields( 10 .addFields(
...@@ -11,7 +13,7 @@ module.exports = { ...@@ -11,7 +13,7 @@ module.exports = {
11 {name: ';checklist', value: "I'll guide you through an anxiety checklist"}, 13 {name: ';checklist', value: "I'll guide you through an anxiety checklist"},
12 {name: ';chat', value: "If you just want a chat with me, I'm all ears!"} 14 {name: ';chat', value: "If you just want a chat with me, I'm all ears!"}
13 ); 15 );
14 - message.channel.send(calmEmbed); 16 + message.channel.send(calm);
15 } 17 }
16 } 18 }
17 19
......
1 +const Discord = require('discord.js');
......
1 +const Discord = require('discord.js');
......
1 -const { MessageEmbed } = require('discord.js'); 1 +const Discord = require('discord.js');
2 const randomPuppy = require('random-puppy'); 2 const randomPuppy = require('random-puppy');
3 3
4 module.exports = { 4 module.exports = {
5 name: 'cute', 5 name: 'cute',
6 - description: 'pulls cute animal pics and embed post', 6 + description: 'Embeds pictures pulled from listed subreddits',
7 - execute(message, args, Discord){ 7 + async run(client, message, args){
8 - let reddit = [ 8 + const subreddits = [
9 "aww", 9 "aww",
10 "puppies", 10 "puppies",
11 "toebeans" 11 "toebeans"
12 ] 12 ]
13 + const random = subreddits[Math.floor(Math.random()*subreddits.length -1)];
14 + const img = await randomPuppy(random);
13 15
14 - let subreddit = reddit[Math.floor(Math.random()*reddit.length -1)]; 16 + const cute = new Discord.MessageEmbed()
17 + .setDescription("Some cute animals to blow away your anxieties!")
18 + .setColor('#91B2C7')
19 + .setURL(`https://reddit.com/r/${random}`)
20 + .setImage(img);
15 21
16 - const cuteEmbed = new MessageEmbed() 22 + message.channel.send(cute);
17 - .setDescription("Some cute animals to blow away your anxieties!");
18 -
19 - randomPuppy(subreddit).then(reponse => {
20 - console.log(url);
21 - const cuteurl = url;
22 -
23 - cuteEmbed.setColor('#91B2C7');
24 - cuteEmbed.setImage('${cuteurl}');
25 - });
26 -
27 - message.channel.send(cuteEmbed);
28 } 23 }
29 } 24 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +const Discord = require('discord.js');
2 +
1 module.exports = { 3 module.exports = {
2 name: 'help', 4 name: 'help',
3 description: 'Directs to ;calm', 5 description: 'Directs to ;calm',
4 - execute(message, args){ 6 + async run(client, message, args){
5 message.channel.send('To see available commands, call me with ;calm'); 7 message.channel.send('To see available commands, call me with ;calm');
6 } 8 }
7 } 9 }
...\ No newline at end of file ...\ No newline at end of file
......
1 +{
2 + "token": "OTgwOTAxNzg3MzY2MjE1Njgw.GVFGdS.z9ily3n-7rcJnqf2FrHg3KJn5h_u68llQzJOGU"
3 +}
...\ No newline at end of file ...\ No newline at end of file
...@@ -5,23 +5,33 @@ const client = new Discord.Client(); ...@@ -5,23 +5,33 @@ const client = new Discord.Client();
5 5
6 const prefix = ';'; 6 const prefix = ';';
7 7
8 +const { token } = require('./config.json'); // hid token in config file
9 +
8 const fs = require('fs'); 10 const fs = require('fs');
11 +const { join } = require('path');
12 +
13 +// Command Handler
9 14
10 client.commands = new Discord.Collection(); 15 client.commands = new Discord.Collection();
11 16
12 const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); 17 const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
13 for(const file of commandFiles){ 18 for(const file of commandFiles){
19 + const commandName = file.split(".")[0];
14 const command = require(`./commands/${file}`); 20 const command = require(`./commands/${file}`);
15 - client.commands.set(command.name, command); 21 + console.log(`Attempting to load command ${commandName}`);
22 + client.commands.set(commandName, command);
16 } 23 }
17 24
25 +//Ready check
26 +
18 client.once('ready', () => { 27 client.once('ready', () => {
19 - console.log('anxietymanager is online') 28 + console.log([...client.commands])
29 + console.log(`anxietymanager is online.`)
20 }); 30 });
21 31
22 32
23 //Command Calls 33 //Command Calls
24 -client.on('message', message => { 34 +client.on('message', async message => {
25 if(!message.content.startsWith(prefix)) return; 35 if(!message.content.startsWith(prefix)) return;
26 36
27 const args = message.content.slice(prefix.length).split(/ +/); 37 const args = message.content.slice(prefix.length).split(/ +/);
...@@ -29,17 +39,17 @@ client.on('message', message => { ...@@ -29,17 +39,17 @@ client.on('message', message => {
29 39
30 if(command == 'ping'){ 40 if(command == 'ping'){
31 message.channel.send('pong!'); 41 message.channel.send('pong!');
32 - } else if(command == 'help'){
33 - client.commands.get('help').execute(message, args);
34 - } else if(command == 'calm'){
35 - client.commands.get('calm').execute(message, args, Discord);
36 - } else if(command == 'breathe'){
37 - client.commands.get('breathe').execute(message, args);
38 - } else if(command == 'cute'){
39 - client.commands.get('cute').execute(message, args, Discord);
40 } 42 }
41 -});
42 43
44 + if(!client.commands.has(command)){
45 + return;
46 + }
43 47
48 + try{
49 + client.commands.get(command).run(client, message, args);
50 + } catch(error){
51 + console.error(error);
52 + }
53 +});
44 54
45 -client.login('OTgwOTAxNzg3MzY2MjE1Njgw.GVFGdS.z9ily3n-7rcJnqf2FrHg3KJn5h_u68llQzJOGU');
...\ No newline at end of file ...\ No newline at end of file
55 +client.login(token);
...\ No newline at end of file ...\ No newline at end of file
......