#Unknown Channel

16 messages · Page 1 of 1 (latest)

real steppe
#

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));
});
dry orioleBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
gray merlin
#

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

real steppe
gray merlin
#

yea the error doesnt seem to come from there tbh

#

are you editing channel overwrites somewhere else perhaps?

real steppe
#

no just there

#

that's why I'm confused

gray merlin
#

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