-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
112 lines (85 loc) · 3.36 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
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
const { Client, GatewayIntentBits, Collection, Events } = require('discord.js')
const quickReplies = require('./commands/context-menu/quick-replies')
require('dotenv').config()
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages]
})
const commandCollection = new Collection()
const contextMenuCommandCollection = new Collection()
contextMenuCommandCollection.set(quickReplies.data.name, quickReplies);
const keyReplyCollection = quickReplies.keyReplyCollection;
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`)
})
client.on('threadCreate', async (thread) => {
if (! thread.joinable) {
return
}
await thread.join()
})
client.on(Events.InteractionCreate, async interaction => {
// Slash commands
if (interaction.isChatInputCommand()) {
const command = commandCollection.get(interaction.commandName)
if (! command) return
try {
await command.execute(interaction)
} catch (e) {
console.error(e)
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true })
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
}
}
// Context menu commands
if (interaction.isMessageContextMenuCommand()) {
const command = contextMenuCommandCollection.get(interaction.commandName)
if (! command) return
try {
await command.execute(interaction)
} catch (e) {
console.error(e)
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true })
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
}
}
if (interaction.isStringSelectMenu()) {
if (interaction.customId !== 'quickReplySelect') {
return
}
try {
const [targetMessageId, key] = interaction.values[0].split(':')
const message = keyReplyCollection.get(key) ?? null
if (! message) {
return
}
const targetMessage = await interaction.channel.messages.fetch(targetMessageId)
await targetMessage.reply({ content: message })
await interaction.reply({
content: `You ran a quick reply command!`,
ephemeral: true,
})
await interaction.deleteReply()
} catch (e) {
console.error(e)
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true })
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true })
}
}
}
})
client.login(process.env.TOKEN).then(() => {
client.user.setPresence({
'activities': [{
'name': 'Filament users',
'type': 'WATCHING',
}],
})
})