-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.js
168 lines (139 loc) · 4.62 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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
const express = require('express');
const morgan = require('morgan');
const dotenv = require('dotenv');
dotenv.config();
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);
});
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('GUARDIAN', { 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);
}
}
});
client.on('guildMemberAdd', (member) => {
const id = member.user.id;
let channel = member.guild.channels.cache.find(
(ch) => ch.id === '807262981657460776'
);
// let channel = member.guild.channels.cache.find(ch => ch.id === '807544047786000417');
if (!channel) return;
embed
.setTitle(':tada: Welcome to the GenXclub Server')
.setColor(0xf1c40f)
.setDescription(
`<@${id}>\nYou're Set to get the "Chosen One" role in 1 Minute, Please be patient - Just Part of Standard Protocols.\n\nEven after few minutes if you aren't able to access Community Space <#806193348669866054>.\n\nPlease contact **@Ninja** for Immediate Assistance.\n\n**In the Mean While Check out these links to know more about us and what we do!**\nGenXclub Instagram: https://www.instagram.com/genxclub/\nTelegram Invite link: https://t.me/genXclub\nYoutube: https://bit.ly/313CeK9\nGitHub: https://github.com/GenXclub\nWebSite: https://genxclub.github.io/index.html`
);
let role = member.guild.roles.cache.find((r) => r.name === 'Chosen One');
setTimeout(setRole, 60000);
member.send(embed);
channel.send(embed).then((msg) => {
msg.delete({ timeout: 50000 });
});
function setRole(embed) {
if (member.roles.cache.has(role.id))
return channel.send('They have that Role.');
member.roles.add(role).catch(console.error);
}
});
// 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(`${emj} ${pg}ms`);
message.channel.send(embed);
}
// Commands list
if (message.content === PREFIX + 'help') {
embed
.setTitle('Command')
.setColor(0x4c8dcf)
.setDescription(
`List of Commands \n\`\`\`?help - <List all the commands> \n?ping - <Latency Information>\n?role - <Self-Assignable Roles>\n?w City/pincode - <Get Weather Information>\`\`\` `
);
message.channel.send(embed);
}
});
client.login(process.env.LEXIS_TOKEN);