-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (50 loc) · 1.67 KB
/
Copy pathindex.js
File metadata and controls
63 lines (50 loc) · 1.67 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
require('dotenv').config()
const fastify = require('fastify')({
logger: true
})
// server so it'll run nicely on the Internet
fastify.get('/', function (request, reply) {
reply.send('honk')
})
fastify.listen(process.env.PORT, function (err, address) {
if (err) {
fastify.log.error(err)
process.exit(1)
}
})
const Discord = require('discord.js')
const client = new Discord.Client({ intents: [Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES] })
const token = process.env.DISCORD_TOKEN
client.on('ready', function () {
console.log('the client becomes ready to start')
console.log(`I am ready! Logged in as ${client.user.tag}!`)
})
client.on('messageCreate', function (message) {
console.log(`message is created -> ${message}`)
if (message.content === 'honk' && message.author.bot === false) {
console.log(`honking ${message.author} from ${client.user}`)
message.channel.send('honk')
} else if (message.author.bot === false) {
console.log(`deleting non-honk message from ${message.author}`)
message.delete()
}
})
client.on('reconnecting', function () {
console.log('client tries to reconnect to the WebSocket')
})
client.on('resume', function (replayed) {
console.log(`whenever a WebSocket resumes, ${replayed} replays`)
})
client.on('warn', function (info) {
console.log(`warn: ${info}`)
})
client.on('error', function (error) {
console.error(`client's WebSocket encountered a connection error: ${error}`)
})
client.on('disconnect', function (event) {
console.log('The WebSocket has closed and will no longer attempt to reconnect')
})
client.on('debug', function (info) {
console.log(`debug -> ${info}`)
})
client.login(token)