.setParent not working after channel name change limits kick in

Hello, I'm new to coding so bear with me. Does anyone know if there's limits to moving channels with .setParent? I'm trying to create a ticket bot, however once the channel name changing limit kicks in (2 changes per 10 minutes from closing/reopening the ticket), I can't use .setParent anymore and the channel doesn't move. I've been stuck trying to figure this out for 2 days (I'm new to coding entirely)
8 Replies
d.js toolkit
d.js toolkit12mo 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!
Danial
Danial12mo ago
You can use <GuildChannel>.edit() instead and do both things in the same API call
d.js docs
d.js docs12mo ago
method GuildChannel#edit() Edits the channel.
Abaddon
AbaddonOP12mo ago
Interesting, thank you; I'll give that a try - I currently do both separately each time it's opened or closed
Danial
Danial12mo ago
Yeah, that's twice as many API calls
Abaddon
AbaddonOP12mo ago
The issue I now run into with this, is that it resets the entire channel permissions instead of just one specific member. Wouldn't it cause more issues trying to configure the entire channels permissions over again when I just need to edit one person within it? Seems I was looking at it the wrong way; doing it this way has worked as I initially intended it to (in regards to modifying permissions) However, it seems once the limiting kicks in for the channel name changes - I can't figure my way around it to continue the rest of the changes and ignore the name change. I'll include my code for the function I've created to do these changes, please keep in mind I'm new to this if it looks horrendous. (the code doesn't do any of the instructions in await channel.edit after the limiting has triggered for channel renaming
async function ticketFunction(channel, updatedName, archivedTicketsId, reportsCategoryId, ticketCreatorGrabbed) {
const guild = client.guilds.cache.get('1083799238707794000');
const roleNames = ['Veteran Member'];
const roles = roleNames.map((roleName) => {
const role = guild.roles.cache.find((r) => r.name === roleName);
if (role) {
return role;
} else {
throw new Error(`Role "${roleName}" not found.`);
}
});

const channelId = channel.id;
let success = false;
console.log(`Channel ID in function: ${channelId}`)

if (channel) {
console.log(`Ticket Function Start`);
// ticket reopen
console.log(`Channel Parent: ${channel.parentId}`);
console.log(`Archived Category Log: ${archivedTicketsId}`);
console.log(`Reports Category Log: ${reportsCategoryId}`);
if (channel.parentId === archivedTicketsId) {
console.log(`Ticket Reopen`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Reopen Try`);

try {
await channel.edit({
name: updatedName,
parent: reportsCategoryId,
permissionOverwrites: [
{
id: ticketCreatorGrabbed,
allow: ['ViewChannel']
},
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});
} catch (e) {
console.log(`Reopen/Parent Setting Error ${e}`);
return;
}

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (close_setname_error) {
console.log(`Re-Open SetName Error: ${close_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
} else if (channel.parentId === reportsCategoryId) {
console.log(`Ticket Close`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Close Try`);

await channel.edit({
name: updatedName,
parent: archivedTicketsId,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (reopen_setname_error) {
console.log(`Re-Open SetName Error: ${reopen_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
}
} else {
console.log(`Error234234`);
}
return success
}
async function ticketFunction(channel, updatedName, archivedTicketsId, reportsCategoryId, ticketCreatorGrabbed) {
const guild = client.guilds.cache.get('1083799238707794000');
const roleNames = ['Veteran Member'];
const roles = roleNames.map((roleName) => {
const role = guild.roles.cache.find((r) => r.name === roleName);
if (role) {
return role;
} else {
throw new Error(`Role "${roleName}" not found.`);
}
});

const channelId = channel.id;
let success = false;
console.log(`Channel ID in function: ${channelId}`)

if (channel) {
console.log(`Ticket Function Start`);
// ticket reopen
console.log(`Channel Parent: ${channel.parentId}`);
console.log(`Archived Category Log: ${archivedTicketsId}`);
console.log(`Reports Category Log: ${reportsCategoryId}`);
if (channel.parentId === archivedTicketsId) {
console.log(`Ticket Reopen`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Reopen Try`);

try {
await channel.edit({
name: updatedName,
parent: reportsCategoryId,
permissionOverwrites: [
{
id: ticketCreatorGrabbed,
allow: ['ViewChannel']
},
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});
} catch (e) {
console.log(`Reopen/Parent Setting Error ${e}`);
return;
}

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (close_setname_error) {
console.log(`Re-Open SetName Error: ${close_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
} else if (channel.parentId === reportsCategoryId) {
console.log(`Ticket Close`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Close Try`);

await channel.edit({
name: updatedName,
parent: archivedTicketsId,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (reopen_setname_error) {
console.log(`Re-Open SetName Error: ${reopen_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
}
} else {
console.log(`Error234234`);
}
return success
}
I added the code below as well, I read through this discord and online to try this to log the rate limiting information but it doesn't output anything to the console once I've triggered it.
client.on('rateLimit', (rateLimitInfo) => {
console.log('Rate limit hit!');
console.log(rateLimitInfo);
// You can log or handle the rate limit information here
});
client.on('rateLimit', (rateLimitInfo) => {
console.log('Rate limit hit!');
console.log(rateLimitInfo);
// You can log or handle the rate limit information here
});
It's definitely that though, as after I've triggered it by changing the channel name twice; it will complete the code after 10 minutes has passed Thank you, was everything else for the rate limit portion correct? After adding the change you mentioned, it still doesn't seem to output anything despite the rate limit being triggered I added this under where by bot starts:
client.rest.on('rateLimited', (rateLimitInfo) => {
console.log('Rate limit hit!');
console.log(rateLimitInfo);
// You can log or handle the rate limit information here
});
client.rest.on('rateLimited', (rateLimitInfo) => {
console.log('Rate limit hit!');
console.log(rateLimitInfo);
// You can log or handle the rate limit information here
});
My package file has "discord.js": "^14.14.1" and the client is correct I've been trying to solve this for a few days on my own before I decided to ask for help here; cannot figure it out for the life of me
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
+-- @discordjs/[email protected]
| `-- [email protected] deduped
I am, all the code works as intended up until the rate limit is triggered, at which point it stops entirely. In the code below, it reaches the console log Ticket Close Try then stops completely; once 10 minutes passes it will finish where it left off.
else if (channel.parentId === reportsCategoryId) {
console.log(`Ticket Close`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Close Try`);

try {
await channel.edit({
name: updatedName,
parent: archivedTicketsId,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});
} catch (e) {
console.log(`Close/Parent Setting Error ${e}`)
}

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (close_setname_error) {
console.log(`Close SetName Error: ${close_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
}
else if (channel.parentId === reportsCategoryId) {
console.log(`Ticket Close`);
console.log(`Success: ${success}`)
try {
console.log(`Ticket Close Try`);

try {
await channel.edit({
name: updatedName,
parent: archivedTicketsId,
permissionOverwrites: [
{
id: guild.roles.everyone,
deny: ['ViewChannel']
},
...roles.map((role) => ({
id: role.id,
allow: ['ViewChannel']
})),
]
});
} catch (e) {
console.log(`Close/Parent Setting Error ${e}`)
}

console.log(`Name Update Attempt: ${updatedName}`);
console.log(`Move Attempt: ${updatedName}`);
success = true
console.log(`Success: ${success}`)
} catch (close_setname_error) {
console.log(`Close SetName Error: ${close_setname_error}`);
console.log(`Name Update Attempt Failed: ${updatedName}`);
}
}
I put this inside of my app.js, where the rest of all my code is; is that what you want?
d.js docs
d.js docs12mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
Abaddon
AbaddonOP12mo ago
Alright, one moment - apologies in advance because it will most likely look confusing to someone other than myself Forgive me, I'd like to make sure I do this correctly. So I need to add
rest: {rejectOnRateLimit: true}
rest: {rejectOnRateLimit: true}
into the client and where exactly would I want to place the console log? Above my channel.edit attempt? My end goal of this essentially would be to add something for when this limiting does happen, I can handle that in a different way than queuing it for later I just read that I need to know what type of "limit" it is in order to try and do that I wasn't able to log anything so I couldn't figure out what to do with it When I ran it like this, I had "true 1" output in the console (before the channel.edit) and it didn't do any of the edits like you said It logged once immediately, despite the limit not being reached (but ran the code) It logs once every time No, I don't by hang do you mean stop running the code? It outputs the "true 1" message every time, but only stops the code once the limit is triggered Sorry I think I'm explaining myself poorly Once the limit is triggered, it now skips over the channel.edit After commenting that, it stops the code once it outputs true 1 If by twice you mean: true 1 true 1 No, it does not It outputs true 1 each time I close/reopen, then on the attempt when the limit is triggered it outputs true 1 and stops completely Right, will do
Logged in as: SCP Site Roleplay Test#5578
Close1
Close2
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463610173665331
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Close
Success: false
Ticket Close Try
true 1
Name Update Attempt: closed-game-80
Move Attempt: closed-game-80
Success: true
After Channel Stuff
Close4
Close5
Close7
Close8
Close6
Reopen1
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463734408953897
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Reopen
Success: false
Ticket Reopen Try
true 1
Name Update Attempt: game-80
Move Attempt: game-80
Success: true
Close4
Reopen3
Close1
Close2
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463610173665331
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Close
Success: false
Ticket Close Try
true 1
Logged in as: SCP Site Roleplay Test#5578
Close1
Close2
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463610173665331
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Close
Success: false
Ticket Close Try
true 1
Name Update Attempt: closed-game-80
Move Attempt: closed-game-80
Success: true
After Channel Stuff
Close4
Close5
Close7
Close8
Close6
Reopen1
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463734408953897
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Reopen
Success: false
Ticket Reopen Try
true 1
Name Update Attempt: game-80
Move Attempt: game-80
Success: true
Close4
Reopen3
Close1
Close2
Channel ID in function: 1184961015964770355
Ticket Function Start
Channel Parent: 1154463610173665331
Archived Category Log: 1154463734408953897
Reports Category Log: 1154463610173665331
Ticket Close
Success: false
Ticket Close Try
true 1
Sorry, I'm poor at explaining myself lol This is closing and reopening until the limit triggers I do, it does seem silly but as I'm new to this I'm trying to make sure I understand what's happening when I go through and fix things Doing my best to learn myself before trying to get help (like this) - but I've been stuck for days In my code, my end goal is that if this limit is triggered, I will be doing the same channel.edit but removing the portion that changes the name to respect the limit Is there some sort of other way to do this? My impression that it was possible is the popular ticket tool bot can close/reopen tickets (and rename) twice, then it only does permission setting and channel moving unless that'd need to be done outside of a channel.edit instead I'm not sure I understand then; when I open/close tickets using tickettool.xyz, I can (seemingly infinitely) reopen/close tickets in quick succession, the only thing that stops working is once its been done twice the channel name no longer changes but the rest continues immediately
Want results from more Discord servers?
Add your server