Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (66 loc) · 2.3 KB
/
Copy pathindex.js
File metadata and controls
85 lines (66 loc) · 2.3 KB
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
const Discord = require('discord.js');
const botClient = require("./structures/botClient");
const client = new botClient();
const owner = process.env.Owner;
const prefix = process.env.Prefix;
const Token = process.env.Token;
const fs = require('fs');
const cmdir = './commands';
client.commands = new Discord.Collection();
// commands init
const commandFiles = fs.readdirSync(cmdir).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`${cmdir}/${file}`);
// set a new item in the Collection
// with the key as the command name and the value as the exported module
client.commands.set(command.name, command);
console.log(`Loading: ${file} as ${command.name}`)
// set if there aliase !== null
// // with the key as the each of command aliases and the value as the exported module
command.aliases.map(e=>{
// console.log(e);
client.commands.set(e, command);
console.log(`Loading: ${file} as ${e}`)
})
}
// event Handler
client.on('message', message => {
// message.channel.send(message.content);
// if people mention us, tell them about our prefix
if(message.mentions.users.size){
console.log("ada")
if(message.mentions.users.first().id == client.user.id){
return message.reply(`my prefix is \`\`${prefix}\`\``)
}
}
// if user message by DM
if(message.guild == null){
// doing nothing
return;
}
// check message with prefix
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
// if no command like this do nothing
if (!client.commands.has(command)) return;
var comid = client.commands.get(command);
// only owner
if (comid.admin && message.author.id !== owner )return message.reply("only owner can access this command!");
// only on nsfw channel
if (comid.nsfw && !message.channel.nsfw) return message.reply("require NSFW channel! so can't run command!")
try {
comid.execute(client,message, args);
} catch (error) {
console.error(error);
message.reply('there was an error trying to execute that command!');
}
});
client.once('ready', () => {
console.log(client.user.username+' is Ready!');
});
client.login(Token)
.then(e=>{
require("./webserver.js").execute(client);
})
.catch(err=>console.log(err));