Not creating channel overwrites

const rolename = roleToClone.name;
const rolecolor = roleToClone.color;
const roleposition = roleToClone.position;
const rolepermissions = roleToClone.permissions;
const rolementionable = roleToClone.mentionable;
const rolehoist = roleToClone.hoist;

try {
// Clone role
const clonedRole = await interaction.guild.roles.create({
name: rolename,
color: rolecolor,
permissions: rolepermissions,
position: roleposition,
mentionable: rolementionable,
hoist: rolehoist
});



interaction.guild.channels.cache.forEach(async (channel) => {
const existingOverwrites = channel.permissionOverwrites.cache.get(roleToClone.id);
if (existingOverwrites) {
await channel.permissionOverwrites.edit(clonedRole, {
id: channel.id,
allow: existingOverwrites.allow,
deny: existingOverwrites.deny,
});
} else {s
return;
}
});
const rolename = roleToClone.name;
const rolecolor = roleToClone.color;
const roleposition = roleToClone.position;
const rolepermissions = roleToClone.permissions;
const rolementionable = roleToClone.mentionable;
const rolehoist = roleToClone.hoist;

try {
// Clone role
const clonedRole = await interaction.guild.roles.create({
name: rolename,
color: rolecolor,
permissions: rolepermissions,
position: roleposition,
mentionable: rolementionable,
hoist: rolehoist
});



interaction.guild.channels.cache.forEach(async (channel) => {
const existingOverwrites = channel.permissionOverwrites.cache.get(roleToClone.id);
if (existingOverwrites) {
await channel.permissionOverwrites.edit(clonedRole, {
id: channel.id,
allow: existingOverwrites.allow,
deny: existingOverwrites.deny,
});
} else {s
return;
}
});
11 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!
Mike | Team BG
Mike | Team BGOP12mo ago
Tried that and still gave me this: Unhandled Rejection at: Promise { <rejected> TypeError: Cannot read properties of undefined (reading 'cache') at E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:46:73 at _Collection.forEach (<anonymous>) at Object.execute (E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:45:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (E:\Bot_Development\TeamBG4.2\src\events\interactionCreate.js:15:13) } reason: TypeError: Cannot read properties of undefined (reading 'cache') at E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:46:73 at _Collection.forEach (<anonymous>) at Object.execute (E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:45:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (E:\Bot_Development\TeamBG4.2\src\events\interactionCreate.js:15:13)
treble/luna
treble/luna12mo ago
log channel thats the one i was thingking which ones didnt have overwrites
Mike | Team BG
Mike | Team BGOP12mo ago
There are no threads in the channel in question. Plus I think that my handler for finding if there are overwrites present should accommodate that correct? I still don't know what you mean by that
d.js docs
d.js docs12mo ago
mdn console: log() static method The console.log() static method outputs a message to the console. The message may be a single string (with optional substitution values), or it may be any one or more JavaScript objects.
treble/luna
treble/luna12mo ago
but your issue probably is waht qjuh mentioned
Mike | Team BG
Mike | Team BGOP12mo ago
So filter by channel type of text, voice, stage, forum, announcement, and category
treble/luna
treble/luna12mo ago
just check if the channel has permissionOverwrites
Mike | Team BG
Mike | Team BGOP12mo ago
I thought it already does that? Doesn't it?
treble/luna
treble/luna12mo ago
if it did you wouldnt have this issue it would make no sense to filter everything separately if you can just check for permissionOverwrites being present or not
Mike | Team BG
Mike | Team BGOP12mo ago
Now I'm getting this: Unhandled Rejection at: Promise { <rejected> TypeError [InvalidType]: Supplied overwrites is not an Array or Collection of Permission Overwrites. at PermissionOverwriteManager.set (E:\Bot_Development\TeamBG4.2\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:68:9) at E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:49:56 at _Collection.forEach (<anonymous>) at Object.execute (E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:45:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (E:\Bot_Development\TeamBG4.2\src\events\interactionCreate.js:15:13) { code: 'InvalidType' } } reason: TypeError [InvalidType]: Supplied overwrites is not an Array or Collection of Permission Overwrites. at PermissionOverwriteManager.set (E:\Bot_Development\TeamBG4.2\node_modules\discord.js\src\managers\PermissionOverwriteManager.js:68:9) at E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:49:56 at _Collection.forEach (<anonymous>) at Object.execute (E:\Bot_Development\TeamBG4.2\src\commands\Moderation\clone.js:45:46) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async Object.execute (E:\Bot_Development\TeamBG4.2\src\events\interactionCreate.js:15:13) { code: 'InvalidType' }
Want results from more Discord servers?
Add your server