When I'm trying to change the channel permissions to lock users from sending messages, this error pops up no matter what I do.
TypeError: channel.updateOverwrite is not a function
Is there anything wrong?
module.exports =
{
async execute(message, args)
{
const role = message.guild.roles.cache.find(r => r.name === '@everyone')
let channel = message.mentions.channels.first() || args[0]
if(!channel) channel = message.channel
if(channel.permissionsFor(message.guild.id).has('SEND_MESSAGES') === false) return message.channel.send(`${channel} is already locked.`)
await channel.updateOverwrite(message.guild.id, { SEND_MESSAGES: false }).catch(() => {}) // Line in which the error happens
await channel.updateOverwrite(role, { SEND_MESSAGES: false} ).catch(() => {})
}
}
It seems you're using discord.js v13 but using some old code. In v13 the channel#updateOverwrite()
method is removed and while in previous version channel#permissionOverwrites
was a collection of overwrites, in v13 it's a PermissionOverwriteManager
. It means, you should use its .edit()
method to update overwrites:
await channel
.permissionOverwrites.edit(message.guild.id, { SEND_MESSAGES: false })
await channel
.permissionOverwrites.edit(role, { SEND_MESSAGES: false })