Skip to content

Commit

Permalink
Merge staging into main
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] authored Jun 4, 2023
2 parents 5034c03 + f5b2397 commit 6e86b4b
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/managers/guild-ticket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type ButtonInteraction,
EmbedBuilder,
type GuildMemberResolvable,
PermissionFlagsBits,
TextChannel,
type TextChannelResolvable
} from 'discord.js'
Expand Down Expand Up @@ -57,23 +58,17 @@ export default class GuildTicketManager extends DataManager<number, Ticket, Tick
}

const channelName = `${ticketType.name}-${author.user.tag}`
const permissionOverwrites = this.context.ticketsCategory?.permissionOverwrites.cache.toJSON() ?? []
let channel
try {
channel = await this.context.guild.channels.create({
name: channelName,
parent: this.context.ticketsCategory ?? undefined
parent: this.context.ticketsCategory ?? undefined,
permissionOverwrites: [...permissionOverwrites, {
id: author.id,
allow: [PermissionFlagsBits.ViewChannel]
}]
})

// In random occassions on the Twin-Rail server, the permission overwrites
// creation shows up in the audit log but not actually in the channel's
// permissions tab. Force fetch the channel from the API first to make
// sure it was created before creating the permission overwrites.
channel = await this.context.guild.channels.fetch(channel.id, { force: true })
if (channel === null || !channel.isTextBased() || channel.isThread()) {
throw new Error('Could not find channel.')
}

await channel.permissionOverwrites.create(author, { ViewChannel: true })
} catch (err) {
await channel?.delete()
throw err
Expand Down

0 comments on commit 6e86b4b

Please sign in to comment.