Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit d3a5fc1

Browse files
authored
Merge pull request #2 from esfox/master
Hello. I think I wanna help refactor. :)
2 parents 8a34e70 + c361f6e commit d3a5fc1

File tree

7 files changed

+78
-86
lines changed

7 files changed

+78
-86
lines changed

commands/emmessage.js

Lines changed: 36 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,52 @@
11
require ('dotenv').config()
22
const Discord = require('discord.js');
33
const usedCommand = new Set();
4-
const config = process.env;
4+
const { prefix, ownerID } = process.env;
55

6-
module.exports.run = async (bot, message, args) => {
7-
if(usedCommand.has(message.author.id)){
8-
message.reply("You cannot use " + config.prefix + "emmessage command beacuse of the cooldown.")
9-
} else {
10-
if (message.content.toLowerCase().startsWith(config.prefix + "emmessage")) {
6+
exports.run = (bot, message) => {
117

12-
if(message.author.id !== config.ownerid){
13-
return message.reply("You're not my developer to do that!");
14-
}
8+
const { content, attachments } = message;
159

16-
const contentmsga = message.content.substr(config.prefix.length);
17-
const contentmsg = contentmsga.substr(9);
18-
var Attachment = (message.attachments);
10+
if(usedCommand.has(message.author.id)) {
11+
return message.reply(`You cannot use ${prefix}emmessage command beacuse of the cooldown.`)
12+
}
13+
14+
if(message.author.id !== ownerID) {
15+
return message.reply("You're not my developer to do that!");
16+
}
1917

20-
if(message.attachments.size > 0){
21-
const MEAEmbed = new Discord.MessageEmbed()
22-
.setColor('#b491c8')
23-
.setTitle('Prune Bot | Announcement')
24-
.setAuthor('Join our Discord Server', 'https://i.imgur.com/hKeHeEy.gif', 'https://discord.io/LIMYAW')
25-
.setDescription(contentmsg)
26-
.setThumbnail('https://i.imgur.com/ypxq7B9.png')
27-
.addFields(
28-
{ name: 'Github (Source Code)', value: 'https://github.com/mashwishi/PruneBot' },
29-
{ name: 'Support the Developer:', value: 'https://ko-fi.com/mashwishi' }
30-
)
31-
.setImage(Attachment.array()[0].url)
32-
.setTimestamp()
33-
.setFooter('PruneBot is created by Mashwishi', 'https://i.imgur.com/DxWDaGv.png');
34-
35-
return bot.guilds.cache.array().forEach(guild => guild.owner.send(MEAEmbed));
36-
}
37-
38-
const MEEmbed = new Discord.MessageEmbed()
39-
.setColor('#b491c8')
40-
.setTitle('Prune Bot | Announcement')
41-
.setAuthor('Join our Discord Server', 'https://i.imgur.com/hKeHeEy.gif', 'https://discord.io/LIMYAW')
42-
.setDescription(contentmsg)
43-
.setThumbnail('https://i.imgur.com/ypxq7B9.png')
44-
.addFields(
45-
{ name: 'Github (Source Code)', value: 'https://github.com/mashwishi/PruneBot' },
46-
{ name: 'Support the Developer:', value: 'https://ko-fi.com/mashwishi' }
47-
)
48-
.setTimestamp()
49-
.setFooter('PruneBot is created by Mashwishi', 'https://i.imgur.com/DxWDaGv.png');
50-
bot.guilds.cache.array().forEach(guild => guild.owner.send(MEEmbed));
18+
const description = content.substr(prefix.length).substr(9);
19+
const embed = new Discord.MessageEmbed()
20+
.setColor('#b491c8')
21+
.setTitle('Prune Bot | Announcement')
22+
.setAuthor(
23+
'Join our Discord Server',
24+
'https://i.imgur.com/hKeHeEy.gif',
25+
'https://discord.io/LIMYAW',
26+
)
27+
.setDescription(description)
28+
.setThumbnail('https://i.imgur.com/ypxq7B9.png')
29+
.addFields([
30+
{ name: 'Github (Source Code)', value: 'https://github.com/mashwishi/PruneBot' },
31+
{ name: 'Support the Developer:', value: 'https://ko-fi.com/mashwishi' }
32+
])
33+
.setFooter('PruneBot is created by Mashwishi', 'https://i.imgur.com/DxWDaGv.png')
34+
.setTimestamp();
5135

52-
}
53-
usedCommand.add(message.author.id);
54-
setTimeout(() => {
55-
usedCommand.delete(message.author.id);
56-
}, 5000);
36+
if(attachments.size > 0) {
37+
embed.setImage(attachments.first().url)
5738
}
39+
40+
bot.guilds.cache.array().forEach(guild => guild.owner.send(embed));
41+
42+
usedCommand.add(message.author.id);
43+
setTimeout(() => usedCommand.delete(message.author.id), 5000);
5844
}
5945

60-
module.exports.config = {
46+
exports.config = {
6147
name: "emmessage",
6248
description: "",
6349
usage: "?emmessage",
6450
accessableby: "Admins",
6551
aliases: []
66-
}
52+
}

events/guildMemberAdd.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = member => {
2+
//const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')
3+
//welcomeChannel.send (`Welcome! ${member}`)
4+
}

events/index.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const ready = require("./ready");
2+
const guildMemberAdd = require("./guildMemberAdd");
3+
4+
module.exports = bot => {
5+
bot.on("ready", () => ready(bot));
6+
bot.on("guildMemberAdd", guildMemberAdd);
7+
}

events/ready.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const Discord = require("discord.js")
22

3-
module.exports = bot => {
3+
module.exports = bot => {
44
console.log(`${bot.user.username} is online`)
55
bot.user.setActivity('this server.', { type: 'WATCHING' });
66
}

index.js

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,50 @@
11
require ('dotenv').config()
22
const Discord = require('discord.js');
3-
const config = process.env;
3+
const { readdirSync } = require("fs");
4+
const handleEvents = require("./events");
45

6+
const config = process.env;
57
const bot = new Discord.Client({disableEveryone: true});
68

7-
bot.on("guildMemberAdd", member => {
8-
//const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')
9-
//welcomeChannel.send (`Welcome! ${member}`)
10-
})
11-
12-
require("./util/eventHandler")(bot)
9+
handleEvents(bot);
1310

14-
const fs = require("fs");
1511
bot.commands = new Discord.Collection();
1612
bot.aliases = new Discord.Collection();
1713

18-
fs.readdir("./commands/", (err, files) => {
19-
20-
if(err) console.log(err)
21-
22-
let jsfile = files.filter(f => f.split(".").pop() === "js")
23-
if(jsfile.length <= 0) {
24-
return console.log("[LOGS] Couldn't Find Commands!");
14+
try
15+
{
16+
let files = readdirSync("./commands/");
17+
let jsfiles = files.filter(f => f.split(".").pop() === "js")
18+
if(jsfiles.length <= 0) {
19+
return console.log("[LOGS] Couldn't Find Commands!");
2520
}
2621

27-
jsfile.forEach((f, i) => {
22+
jsfiles.forEach(f => {
2823
let pull = require(`./commands/${f}`);
29-
bot.commands.set(pull.config.name, pull);
24+
bot.commands.set(pull.config.name, pull);
3025
pull.config.aliases.forEach(alias => {
3126
bot.aliases.set(alias, pull.config.name)
3227
});
3328
});
34-
});
3529

36-
bot.on("message", async message => {
37-
if(message.author.bot || message.channel.type === "dm") return;
30+
bot.on("message", message => {
31+
if(message.author.bot || message.channel.type === "dm") return;
3832

39-
let prefix = config.prefix;
40-
let messageArray = message.content.split(" ");
41-
let cmd = messageArray[0];
42-
let args = message.content.substring(message.content.indexOf(' ')+1);
33+
let { content } = message;
34+
let { prefix } = config;
35+
if(!content.startsWith(prefix)) return;
4336

44-
if(!message.content.startsWith(prefix)) return;
45-
let commandfile = bot.commands.get(cmd.slice(prefix.length)) || bot.commands.get(bot.aliases.get(cmd.slice(prefix.length)))
46-
if(commandfile) commandfile.run(bot,message,args)
37+
let [ cmd, args ] = content.split(/\s(.+)/);
38+
cmd = cmd.slice(prefix.length);
4739

48-
})
40+
let commandfile = bot.commands.get(cmd) || bot.commands.get(bot.aliases.get(cmd))
41+
if(commandfile) commandfile.run(bot, message, args)
42+
})
4943

50-
bot.login(process.env.token);
44+
bot.login(process.env.TOKEN);
45+
}
46+
catch(error)
47+
{
48+
console.log("Cannot load command files");
49+
console.log(error);
50+
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "PruneBot",
33
"version": "1.0.0",
44
"description": "A Discord Moderation Bot",
5-
"main": "mybot.js",
5+
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},

util/eventHandler.js

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)