Created
November 2, 2020 13:23
-
-
Save Mystik01/b7ef796b44058dff7c23c0f12ceeaebf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
client.on('messageReactionAdd', async (reaction, user, channel, message, TextChannel) => { | |
if (user.bot) return; | |
if (reaction.emoji.name === '📩') { | |
const ticketConfig = await TicketConfig.findOne({ where: { messageId: reaction.message.id } }); | |
if (ticketConfig) { | |
const findTicket = await Ticket.findOne({ where: { authorId: user.id, resolved: false } }); | |
if (findTicket) user.send('Please find your open ticket in the discord for help.') && reaction.users.remove(user.id); | |
else { | |
console.log('Creating ticket'); | |
try { | |
const roleIdsString = ticketConfig.getDataValue('roles'); | |
console.log("role id string") | |
console.log(roleIdsString); | |
const roleIds = JSON.parse(roleIdsString); | |
console.log("roleIds below") | |
console.log(roleIds); | |
const permissions = roleIds.map((id) => ({ allow: 'VIEW_CHANNEL', id })); | |
const channel = await reaction.message.guild.channels.create('dev', { | |
parent: ticketConfig.getDataValue('parentId'), | |
permissionOverwrites: [ | |
{ deny: 'VIEW_CHANNEL', id: reaction.message.guild.id }, | |
{ allow: 'SEND_MESSAGES', id: user.id }, | |
{ allow: 'VIEW_CHANNEL', id: user.id }, | |
...permissions | |
] | |
}); | |
reaction.users.remove(user.id) | |
const ticketlog = ticketConfig.getDataValue('loggingChannelId'); | |
console.log(ticketlog) | |
(await client.channels.fetch(ticketlog)).send("test") | |
const msg = await channel.send("<@" + (user.id) + ">" + '\nPlease explain what you need support with - Our Moderator Team will get back to you as soon as possible.\nReact below with the 🚫 emoji to close this ticket. '); | |
const msgCategory = await channel.send(SupportMSG) | |
await msg.react('🚫'); | |
await msgCategory.react('1️⃣'), | |
await msgCategory.react('2️⃣'), | |
await msgCategory.react('3️⃣'), | |
await msgCategory.react('4️⃣'); | |
msg.pin(); | |
const ticket = await Ticket.create({ | |
authorId: user.id, | |
channelId: channel.id, | |
guildId: reaction.message.guild.id, | |
resolved: false, | |
closedMessageId: msg.id | |
}); | |
const ticketId = String(ticket.getDataValue('ticketId')).padStart(4, 0); | |
await channel.edit({ name: `dev-${ticketId}` }) | |
} catch (err) { | |
console.log(err); | |
client.users.cache.get(owner).send(err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment