Creation of a channel and adds a role to this channel

Hello! Sometimes, not always, when my bot creates a new channel for a ticket system, it doesn't add the role configured in my ticket system, but in the audit logs, it appears. Do you have any idea why ? Thank you
8 Replies
d.js toolkit
d.js toolkit14mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Kirito.
Kirito.OP14mo ago
No description
No description
Parogo_72
Parogo_7214mo ago
Code
Kirito.
Kirito.OP14mo ago
const ticketCreate = await guild.channels.create({
name: `${nameChannel.toLowerCase()}-${numberTicket}`,
type: 0,
parent: categoryDb,
permissionOverwrites:
[
{
id: guild.id,
deny: [PermissionsBitField.Flags.ViewChannel]
},
{
id: inter.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.AttachFiles]
},
{
id: this.client.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.AttachFiles]
}],
reason: `${this.event.translate(inter.user.id, 'eventTicketNewTicketReason').replace('{user}', user.displayName)}`
}).catch(() => null);

if (inter.guild.roles.cache.get(roleId)) await ticketCreate.permissionOverwrites.create(roleId, {
ViewChannel: true,
SendMessages: true,
EmbedLinks: true,
AttachFiles: true
}, {
type: 0
}).catch(() => null);
const ticketCreate = await guild.channels.create({
name: `${nameChannel.toLowerCase()}-${numberTicket}`,
type: 0,
parent: categoryDb,
permissionOverwrites:
[
{
id: guild.id,
deny: [PermissionsBitField.Flags.ViewChannel]
},
{
id: inter.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.AttachFiles]
},
{
id: this.client.user.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.EmbedLinks, PermissionsBitField.Flags.AttachFiles]
}],
reason: `${this.event.translate(inter.user.id, 'eventTicketNewTicketReason').replace('{user}', user.displayName)}`
}).catch(() => null);

if (inter.guild.roles.cache.get(roleId)) await ticketCreate.permissionOverwrites.create(roleId, {
ViewChannel: true,
SendMessages: true,
EmbedLinks: true,
AttachFiles: true
}, {
type: 0
}).catch(() => null);
Sometimes it works, sometimes not
Parogo_72
Parogo_7214mo ago
Why dont you put it inside the permissionOverwrites? Why do you make a separated call for that role, instead of putting it along with the everyone role and the user
Kirito.
Kirito.OP14mo ago
It's not a problem to put it inside permissionOverwrites if the roleId can be null ?
Parogo_72
Parogo_7214mo ago
You can check if its null before adding it to the array though
Kirito.
Kirito.OP14mo ago
Yes why not, I will try Thank you Same problem, it appears in the log, but not on the channel permissions, maybe a bug from discord because it works perfectly before and I haven't change anything edit : I have added the type for each permissionOverwrites and it works again 👍
Want results from more Discord servers?
Add your server