-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
56 lines (50 loc) · 2.45 KB
/
index.js
File metadata and controls
56 lines (50 loc) · 2.45 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
// config.json variables are commented out, .env variables are used here
/*const {
prefix,
token,
} = require('./config.json');*/
require('dotenv').config();
// import dependencies, and variables from our json file
const { Client, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
// create client and login with our token
// client.login(token);
client.login(process.env.TOKEN);
// basic bot listeners that trigger when executed
client.once('ready', () => {
console.log('Ready!');
});
client.once('reconnecting', () => {
console.log('Reconnecting!');
});
client.once('disconnect', () => {
console.log('Disconnect!');
});
// read chat message and respond to them
// create listener for message event and save it in message object
client.on('messageCreate', async message => {
if (message.author.bot) return; // if our own bot wrote the message we ignore it
// if (!message.content.startsWith(prefix)) return; // if message doesnt start with our defined prefix we return
if (!message.content.startsWith(process.env.PREFIX)) return; // if message doesnt start with our defined prefix we return
// check which command to execute
//if (message.content.startsWith(`${prefix}name`)){
if (message.content.startsWith(`${process.env.PREFIX}name`)){
message.reply(`Your name is ${message.author.username}`);
return;
} //else if (message.content.startsWith(`${prefix}greeting`)){
else if (message.content.startsWith(`${process.env.PREFIX}greeting`)){
message.channel.send("Hello world!");
return;
} //else if (message.content.startsWith(`${prefix}secret`)){
else if (message.content.startsWith(`${process.env.PREFIX}secret`)){
message.author.send("Shhh! This is a secret message for you");
return;
} //else if (message.content.startsWith(`${prefix}quote`)){
else if (message.content.startsWith(`${process.env.PREFIX}quote`)){
const quoteEmbed = new MessageEmbed().setColor("ORANGE").setTitle(`Quote for ${message.author.username}`).setURL("https://discord.js.org/#/docs/discord.js/stable/class/Client").setDescription("To be, or not to be. That is the question.")
message.channel.send({embeds: [quoteEmbed]});
return;
} else {
message.channel.send("You need to enter a valid command!"); // if invalid command, send this error message to the channel
}
})