-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
85 lines (79 loc) · 2.37 KB
/
index.js
File metadata and controls
85 lines (79 loc) · 2.37 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
let Discord = require('discord.js');
let client = new Discord.Client();
client.on('ready', () => {
console.log('Logged in as ' + client.user.tag);
client.channels.cache.find(channel => channel.name == 'channel-name-no-hashtag').send('hi');
});
client.on('message', msg => {
if (msg.content == 'ping') {
msg.reply('Pong!');
} else if (msg.content.includes('😎')) {
msg.react('😎');
}
})
// Command System
let commands = {
'8ball': {
info: "Ask the Magic 8-ball for a response.", // For help command
run(msg) {
let responses = [
'Yes',
'No',
'Maybe',
'Perhaps',
"That's up to you",
"Ask again later",
"For Certain",
"Unlikely",
// add more if you want
];
let chosen = responses[Math.floor(Math.random() * responses.length)];
msg.reply(chosen);
},
},
'8-ball': '8ball', // Alias
'random': {
syntax: 'random [number]',
info: 'Generate a random number between 1 and 10, or 1 and a chosen integer.',
run(msg) {
let min = 1;
let max = 10;
let args = msg.content.trim().split(' ');
args.shift(); // pop off first argument
if (args.length >= 1) {
max = Number(args[0]) || max;
}
msg.reply(Math.floor((Math.random() * max) + min));
}
}
};
let prefix = '/';
client.on('message', msg => {
if (msg.content.substr(0, prefix.length) == prefix) {
let cmd = msg.content.substr(prefix.length).split(' ')[0]; // get first word in our command
if (cmd == 'help') { // Show our commands.
msg.reply(
'Commands:\r\n' + Object.entries(commands)
.filter(([key, value]) => typeof value != 'string') // Filter out Alias's
.map(([key, value]) => `${prefix}${value.syntax || key}: ${value.info}`) // Convert our commands to string format
.join('\r\n') // Join by newline
);
} else {
if (cmd in commands) {
let command = commands[cmd];
if (typeof command == 'string') { // Alias support
commands[command].run(msg);
} else {
command.run(msg);
}
} else {
msg.reply("Sorry, I don't know what command you're referring to! Say `" + prefix + "help` for more info.")
}
}
}
})
const TOKEN = "REDACTED";
if (TOKEN == "REDACTED") {
throw new Error("You need to add your bot's own token!")
}
client.login(TOKEN);