-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathticket.js
34 lines (29 loc) · 1.17 KB
/
ticket.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
import { EmbedBuilder } from '@discordjs/builders'
import { ThreadAutoArchiveDuration, ChannelType } from 'discord.js'
import { createTicket, updateTicket, getSubscriptions, formatAncestry } from './db.js'
export const makeTicket = async ({ user, channel, description, node }) => {
const ticketId = createTicket(user.id)
const ancestry = formatAncestry(node)
const name = `[${ticketId}] ${ancestry} (${user.username})`
const thread = await channel.threads.create({
name,
autoArchiveDuration: ThreadAutoArchiveDuration.OneDay,
type: ChannelType.PrivateThread,
invitable: false,
})
updateTicket(ticketId, thread.id)
const embed = new EmbedBuilder()
.setTitle(ancestry)
.setDescription(description)
.setAuthor({
name: user.username,
iconURL: user.avatarURL(),
})
let content = `Use \`/close\` to close this ticket.\n\n${user}`
const subscribers = getSubscriptions(node.id)
if (subscribers.length > 0) {
content += `\nSubscribers: ${subscribers.map(sub => `<@${sub}>`).join(' ')}`
}
await thread.send({ content, embeds: [embed] })
return thread
}