Unknown Channel

I'm using this code below to edit every new channel or an edited channel to deny SendMessages for Mute-Role, and deny ViewChannel for Prison-Role. However I'm getting this weird error in the attachment I sent, and maybe just maybe because there's a ticket bot that created and deleted some channels so how to remove this error?
const MuteR = "MUTEROLEID"
const PrisonR = "PRISONROLEID"
client.on('channelUpdate', async (oldChannel, newChannel) => {
let role = newChannel.guild.roles.cache.get(MuteR);
await newChannel.permissionOverwrites.edit(role.id, {
SendMessages: false,
}).catch(err => console.log(err));
//
let role2 = newChannel.guild.roles.cache.get(PrisonR);
await newChannel.permissionOverwrites.edit(role2.id, {
ViewChannel: false,
}).catch(err => console.log(err));
});

client.on('channelCreate', async (channel) => {
let role = channel.guild.roles.cache.get(MuteR);
await channel.permissionOverwrites.edit(role.id, {
SendMessages: false,
}).catch(err => console.log(err));
//
let role2 = channel.guild.roles.cache.get(PrisonR);
await channel.permissionOverwrites.edit(role2.id, {
ViewChannel: false,
}).catch(err => console.log(err));
});
const MuteR = "MUTEROLEID"
const PrisonR = "PRISONROLEID"
client.on('channelUpdate', async (oldChannel, newChannel) => {
let role = newChannel.guild.roles.cache.get(MuteR);
await newChannel.permissionOverwrites.edit(role.id, {
SendMessages: false,
}).catch(err => console.log(err));
//
let role2 = newChannel.guild.roles.cache.get(PrisonR);
await newChannel.permissionOverwrites.edit(role2.id, {
ViewChannel: false,
}).catch(err => console.log(err));
});

client.on('channelCreate', async (channel) => {
let role = channel.guild.roles.cache.get(MuteR);
await channel.permissionOverwrites.edit(role.id, {
SendMessages: false,
}).catch(err => console.log(err));
//
let role2 = channel.guild.roles.cache.get(PrisonR);
await channel.permissionOverwrites.edit(role2.id, {
ViewChannel: false,
}).catch(err => console.log(err));
});
No description
6 Replies
d.js toolkit
d.js toolkit15mo 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
ShompiFlen
ShompiFlen15mo ago
afaik channelUpdate and channelCreate shouldnt fire on a deleted channel (channelDelete should fire here). So... this kind of doesnt make any sense to me you would be editing a channel that doesnt exist. Maybe try checking if the channel exists beforehand anyways, just in case
Forhand.
Forhand.OP15mo ago
I tried to put if (!newChannel) return; in channelUpdate Event, and if (!channel) return; in channelCreate Event. But still the same
ShompiFlen
ShompiFlen15mo ago
yea the error doesnt seem to come from there tbh are you editing channel overwrites somewhere else perhaps?
Forhand.
Forhand.OP15mo ago
no just there that's why I'm confused
ShompiFlen
ShompiFlen15mo ago
hm... by the way you kind of have a loop here you create a channel, that triggers the channel update event you edit the overwrites there (which i dont get why you dont create the overwrites while creating the channel if you use the bot) that triggers a channelUpdate event, then you again modify the channel thats gonna create an inifite loop also if the channel is deleted in between these events then yea that could create this issue. You see the channel id in the url there? channels/channelId, if you copy that one and try searching for it in your bot channels cache, what happens if its undefined then you will need to look for whatever or whoever deleted that channel your bot was trying to edit
Want results from more Discord servers?
Add your server