-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
107 lines (86 loc) · 2.95 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
const { Client, IntentsBitField, Partials } = require("discord.js");
const { EmbedBuilder, ButtonBuilder, ButtonStyle, ActionRowBuilder, ChannelType, PermissionsBitField } = require('discord.js')
const fs = require('fs')
const WOK = require("wokcommands");
const path = require("path");
const settingFile = fs.readFileSync('./settings.json')
const settings = JSON.parse(settingFile)
require("dotenv/config");
const client = new Client({
intents: [
IntentsBitField.Flags.Guilds,
IntentsBitField.Flags.GuildMessages,
IntentsBitField.Flags.GuildMembers,
IntentsBitField.Flags.DirectMessages,
IntentsBitField.Flags.MessageContent,
],
partials: [Partials.Channel],
});
client.on("ready", () => {
console.log('Bot is online!')
new WOK({
client,
commandsDir: path.join(__dirname, "commands"),
});
});
client.on('interactionCreate', async (interaction) => {
if(interaction.isButton()){
if(interaction.customId === "closeTicket"){
//Check if member who clicked button has admin permissions
if(!interaction.member.permissions.has(PermissionsBitField.Flags.Administrator)){
await interaction.reply({
content: 'You do not have permission to close this ticket',
ephemeral: true
})
return
}
else{
await interaction.channel.delete()
}
}
}
})
client.on('guildMemberAdd', async (member) => {
//Create ticket channel for new member
let channelName = `ticket-${member.user.username}`.toLowerCase()
let everyoneRoleId = member.guild.roles.everyone.id
//Create channel
let channel = await member.guild.channels.create({
name: channelName,
type: ChannelType.GuildText,
permissionOverwrites : [
{
id: member.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages],
},
{
id: everyoneRoleId,
deny: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages],
}
]
})
//Create Embed
let embed = new EmbedBuilder()
.setTitle(settings.embedTitle)
.setDescription(settings.embedDescription)
.setColor(settings.embedColor)
.setFooter({
text: settings.embedFooterText,
iconURL: settings.embedFooterIconURL
})
.setTimestamp()
//Add close button
let closeButton = new ButtonBuilder()
.setStyle(ButtonStyle.Danger)
.setCustomId('closeTicket')
.setLabel('Close Ticket')
//Add action row
let actionRow = new ActionRowBuilder()
.addComponents(closeButton)
//Send embed
await channel.send({
embeds: [embed],
components: [actionRow]
})
})
client.login(process.env.TOKEN);