-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathindex.js
More file actions
156 lines (129 loc) · 6.79 KB
/
index.js
File metadata and controls
156 lines (129 loc) · 6.79 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
// Require Packages
const Discord = require('discord.js');
// Configure Packages
const client = new Discord.Client();
const prefix = ''; // If you would like to add commands to the bot set this here
const ownerID = ''; // Set your ID in here. Do it by copy and pasting it through discord.
const active = new Map();
client.on("error", (e) => console.error(e));
client.on("warn", (e) => console.warn(e));
client.on("debug", (e) => console.info(e));
client.on('ready', () => {
client.user.setGame('Message me for help!');
console.log(`Bot has started, with ${client.users.size} users!`);
});
client.on("guildCreate", guild => {
// This event triggers when the bot joins a guild.
console.log(`${guild.name} SERVER JOINED (id: ${guild.id})! KEEP CAUTION!`);
});
client.on("guildDelete", guild => {
// this event triggers when the bot is removed from a guild.
console.log(`I have been removed from: ${guild.name} (id: ${guild.id})`);
});
const db = require('quick.db');
// Listener Events
client.on('message', async message => {
if (message.author.bot) return;
// Check if Message is in a DM
if (message.guild === null) {
// Fetch Activity Info
let active = await db.fetch(`support_${message.author.id}`);
let guild = client.guilds.get(''); // Your Server ID
let channel, found = true;
try {
if (active) client.channels.get(active.channelID).guild;
} catch(e) {
found = false;
}
if (!active || !found) {
// Create Support Channel.
active = {};
let modRoles = guild.roles.find("name", ""); // Find the Mod/Admin roles so only Admin/Mods will see the tickets. Add it in the quotes
let everyone = guild.roles.find("name","@" + "everyone");
let bot = guild.roles.find("name","Bot");
channel = await guild.createChannel(`${message.author.username}-${message.author.discriminator}`);
channel.setParent(''); // Management Category ID
channel.setTopic(`_complete to close the Ticket | ModMail for ${message.author.tag} | ID: ${message.author.id}`);
channel.overwritePermissions(modRoles, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true,
MANAGE_CHANNELS: true
});
channel.overwritePermissions(everyone, {
VIEW_CHANNEL: false,
});
channel.overwritePermissions(bot, {
VIEW_CHANNEL: true,
SEND_MESSAGES: true,
MANAGE_CHANNELS: true
}); // This will set the permissions so only Staff will see the ticket.
let author = message.author;
const newChannel = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(author.tag, author.displayAvatarURL)
.setFooter('ModMail Ticket Created')
.addField('User', author)
.addField('ID', author.id);
await channel.send(newChannel);
const newTicket = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(`Hello, ${author.tag}`, author.displayAvatarURL)
.setFooter('ModMail Ticket Created');
await author.send(newTicket);
// Update Active Data
active.channelID = channel.id;
active.targetID = author.id;
}
channel = client.channels.get(active.channelID);
const dm = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(`Thank you, ${message.author.tag}`, message.author.displayAvatarURL)
.setFooter(`Your message has been sent -- A staff member will be in contact soon.`);
await message.author.send(dm);
const embed = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setDescription(message.content)
.setFooter(`Message Recieved -- ${message.author.tag}`);
await channel.send(embed);
db.set(`support_${message.author.id}`, active);
db.set(`supportChannel_${channel.id}`, message.author.id);
return;
}
let support = await db.fetch(`supportChannel_${message.channel.id}`);
if (support) {
support = await db.fetch(`support_${support}`);
let supportUser = client.users.get(support.targetID);
if (!supportUser) return message.channel.delete();
// !complete command
if (message.content.toLowerCase() === "_complete") {
const complete = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(`Hey, ${supportUser.tag}`, supportUser.displayAvatarURL)
.setFooter('Ticket Closed')
.setDescription('*Your ModMail has been marked as **Complete**. If you wish to reopen this, or create a new one, please send a message to the bot.*');
supportUser.send(complete);
message.channel.delete()
.then(console.log(`Support for ${supportUser.tag} has been closed.`))
.catch(console.error);
return db.delete(`support_${support.targetID}`);
}
const embed = new Discord.RichEmbed()
.setColor('36393E')
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setFooter(`Message Recieved`)
.setDescription(message.content);
client.users.get(support.targetID).send(embed);
message.delete({timeout: 1000});
embed.setFooter(`Message Sent -- ${supportUser.tag}`).setDescription(message.content);
return message.channel.send(embed);
}
// Variables
let msg = message.content.toUpperCase(); // This takes the message.content, and turns it all uppercase.
let sender = message.author; // This variable holds the message's author.
let args = message.content.slice(prefix.length).trim().split(' '); // This variable takes the message.content, slices off the prefix from the front, then trims the blank spaces on the side, and turns it into an array by separating it by spaces.
let cmd = args.shift().toLowerCase(); // This variable holds the first item from the args array, which is taken off of the args array and turned into lowercase.
// Return Statements
if (!msg.startsWith(prefix)) return; // If the message doesn't start with the prefix, exit the code.
})
client.login(""); //Add the token to your bot user here