-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (29 loc) · 994 Bytes
/
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
const Discord = require("discord.js")
const client = new Discord.Client()
const MongoClient = require('mongodb').MongoClient
MongoClient.connect('mongodb://127.0.0.1:27017', (err, mongo) => {
if (err) {
console.log(err)
return
}
console.log('Connected to MongoDB');
db = mongo.db('discord')
collection = db.collection('log')
client.on('ready', () => {
console.log(`Discord Logged in as ${client.user.tag}!`)
})
client.on('message', msg => {
collection.insertOne({
moment: new Date(),
chanel: msg.channel.name,
userId: msg.author.id,
userName: msg.author.username,
message: msg.content,
words: msg.content.trim().toLowerCase().split(' ').filter((word) => {
return word.replace(/[,\.!()]/g, ' ').trim().match(/^[a-z]{3,16}$/)
}).map((r) => { return r.replace(/[,\.!()]/g, ' ').trim() })
})
console.log(msg.channel.name, msg.author.id, msg.author.username)
})
client.login('...discordbotkey...')
})