-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
75 lines (63 loc) · 2.07 KB
/
index.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
const config = require("./config.json");
const { Client, GatewayIntentBits, Collection } = require("discord.js");
const fs = require("fs");
// Create a new client instance with required intents
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers
],
disableEveryone: true
});
const prefix = config.prefix;
const token = config.token;
client.commands = new Collection();
client.aliases = new Collection();
// Load command files
fs.readdir("./commands/", (err, files) => {
if (err) console.log(err);
let jsfile = files.filter(f => f.split(".").pop() === "js");
if (jsfile.length <= 0) {
console.log("Couldn't find commands.");
return;
}
jsfile.forEach((f, i) => {
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
client.commands.set(props.help.name, props);
props.help.aliases.forEach(alias => {
client.aliases.set(alias, props.help.name);
});
});
});
client.on("ready", async () => {
console.log(`${client.user.username} is ready for action!`);
if (config.activity.streaming == true) {
client.user.setActivity(config.activity.game, { url: 'https://twitch.tv/username' });
} else {
client.user.setActivity(config.activity.game, { type: 'WATCHING' }); // PLAYING, LISTENING, WATCHING
client.user.setStatus('dnd'); // dnd, idle, online, invisible
}
});
client.on("messageCreate", async message => {
if (message.author.bot) return;
if (message.channel.type === "dm") return;
if (!message.content.startsWith(prefix)) return;
let args = message.content.slice(prefix.length).trim().split(/ +/g);
let cmd = args.shift().toLowerCase();
let commandfile;
if (client.commands.has(cmd)) {
commandfile = client.commands.get(cmd);
} else if (client.aliases.has(cmd)) {
commandfile = client.commands.get(client.aliases.get(cmd));
}
if (!commandfile) return;
try {
commandfile.run(client, message, args);
} catch (e) {
console.error(e);
}
});
client.login(token);