Repository navigation
Expand file tree
/
Copy pathIndex.js
More file actions
56 lines (48 loc) · 2.21 KB
/
Copy pathIndex.js
File metadata and controls
56 lines (48 loc) · 2.21 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
const Discord = require('discord.js'); // Require discord.js for your bot to communicate with the Discord API
const config = require('./config.json'); // Our config file
const client = new Discord.Client();
client.on('ready', () => { // When bot is online and ready
console.log(`I'm ready!`);
});
client.on("message", message => { // When the bot spots a message
if(message.author.bot) return; // Doesn't respond to bots
if(message.content.indexOf(config.prefix) !== 0) return; // Only responding to existing commands that start with "!"
const args = message.content.slice(config.prefix.length).trim().split(/ +/g); // Configure arguments for the commands
const command = args.shift().toLowerCase(); // Detect existing commands
//Commands
if(command === "ping") { // "!ping"
message.channel.send('Pong!'); // Send a message saying "Pong!"
}
if (message.content.startsWith("!hello")) {
message.channel.send("Hello!");
}
if (message.content.startsWith("!color")) {
const color = message.content.split(" ")[1];
const roleName = `Color-${color}`;
let role = message.guild.roles.cache.find(r => r.name === roleName);
if (!role) {
role = await message.guild.roles.create({
data: {
name: roleName,
color: color
}
});
}
message.member.roles.add(role);
message.channel.send(`Color changed to ${color}`);
} else if (message.content.startsWith("!recolor")) {
const roleName = "Color-Rainbow";
let role = message.guild.roles.cache.find(r => r.name === roleName);
if (!role) {
role = await message.guild.roles.create({ name: roleName });
}
message.member.roles.add(role);
message.channel.send("Rainbow color mode activated");
const colors = ["#ff0000", "#ffa500", "#ffff00", "#00ff00", "#0000ff", "#800080"];
let i = 0;
setInterval(() => {
role.edit({ color: colors[i++ % colors.length] });
}, 500);
}
});
client.login(config.token); // Log in with the bot token from our config file.