-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
65 lines (55 loc) · 1.43 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
require('dotenv').config();
const { Client, GatewayIntentBits } = require('discord.js');
const nodemailer = require('nodemailer');
const {
DISCORD_TOKEN,
GUILD_ID,
EMAIL_USER,
EMAIL_PASS,
TO_EMAIL,
SMTP_HOST,
SMTP_PORT
} = process.env;
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
]
});
const transporter = nodemailer.createTransport({
host: SMTP_HOST,
port: SMTP_PORT,
secure: false, // true for 465, false for other ports
auth: {
user: EMAIL_USER,
pass: EMAIL_PASS
}
});
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}`);
});
client.on('messageCreate', (message) => {
if (message.guild.id === GUILD_ID && message.mentions.has(client.user)) {
const mailOptions = {
from: EMAIL_USER,
to: TO_EMAIL,
subject: `New @mention in ${message.channel.name}`,
text: `User ${message.author.tag} mentioned in ${message.channel.name}:\n\n${message.content}`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log('Email sent: ' + info.response);
});
}
});
client.on('disconnect', () => {
console.log('Disconnected! Attempting to reconnect...');
client.login(DISCORD_TOKEN);
});
client.on('reconnecting', () => {
console.log('Reconnecting...');
});
client.login(DISCORD_TOKEN);