-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
138 lines (114 loc) · 3.22 KB
/
bot.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
const express = require('express');
const morgan = require('morgan');
const connectDB = require('./api/config/db');
const dotenv = require('dotenv');
dotenv.config();
connectDB();
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
var server = require('http').createServer(app);
if (process.env.NODE_ENV === 'development') {
// Middleware used to log requests.
app.use(morgan('dev'));
}
app.get('/', (req, res) => {
console.log(Date.now() + ' Ping Received');
res.sendStatus(200);
});
// Routes
app.use('/pokemon', require('./api/routes/pokemon'));
// const listener = server.listen(process.env.PORT, function () {
// console.log('Your app is listening on port ' + listener.address().port);
// });
server.listen(process.env.PORT, () => {
console.log(`Your app is listening on port ${server.address().port}`);
});
app.listen(3000, () => {
console.log(`Express Server Running..`);
});
const fs = require('fs');
require('dotenv').config();
prefix = require('./prefix.json');
// obj structuring { }
const {
Client,
WebSocketManager,
MessageEmbed,
Collection,
} = require('discord.js');
const { clear } = require('console');
const client = new Client({
partials: ['MESSAGE', 'REACTION'],
});
// {
// partials: ['MESSAGE', 'REACTION'],
// }
const embed = new MessageEmbed();
const PREFIX = prefix.PREFIX;
client.commands = new Collection();
const Commands = fs
.readdirSync('./commands')
.filter((file) => file.endsWith('.js'));
//Commands Folder
for (const file of Commands) {
const commandList = require(`./commands/${file}`);
client.commands.set(commandList.help.name, commandList);
client.commands.set(commandList.help.aliases, commandList);
}
console.log(Commands.length + ' files loaded in [ commands ] folder');
client.on('ready', () => {
client.user.setActivity('Pokemon Play', { type: 'Playing' });
console.log(`${client.user.tag} has Powered Up!!!`);
});
// Commands folder access.
client.on('message', (message) => {
if (message.author.bot) {
return;
}
let messageArray = message.content.split(' ');
let cmd = messageArray[0];
let args = messageArray.slice(1);
if (
message.content.startsWith(PREFIX) ||
message.content.startsWith(PREFIX.toUpperCase())
) {
CommandHandler();
}
function CommandHandler() {
let commandfile_1 = client.commands.get(cmd.slice(PREFIX.length));
if (commandfile_1) {
commandfile_1.run(client, message, args, messageArray);
}
}
});
// Ping for Devs
client.on('message', (message) => {
if (message.author.bot) return;
if (message.content === 'Prefix' || message.content === 'prefix') {
embed
.setTitle('Prefix - ?')
.setColor(0x4c8dcf)
.setDescription(`\nStart exploration with ?help`);
message.channel.send(embed);
}
// Ping
if (
message.content === PREFIX + 'ping' ||
message.content === PREFIX + 'Ping'
) {
const pg = Math.round(client.ws.ping);
let emj;
if (pg <= 100) {
emj = ':green_circle:';
} else {
emj = ':red_circle:';
}
embed
.setTitle('')
.setColor(0x4c8dcf)
.setDescription(`**🛰️ Bot Responed ${emj} ${pg}ms**`);
message.channel.send(embed);
}
});
client.login(process.env.PP_TOKEN);