I’m following a tutorial on discord.js, making a ticket bot. I have double-checked and I am still getting the same error:
TypeError: channel.updateOverwrite is not a function
I’ve looked over all the StackOverflow questions that I could find, but none has worked for me. I have also explored a little deeper outside of SO, still no help. Here is my code:
JavaScript
x
50
50
1
module.exports = {
2
name: 'ticket',
3
description: 'Open a ticket!',
4
async execute(client, message, args, cmd, Discord) {
5
// creates tickets
6
let channel = await message.guild.channels.create(
7
`ticket: ${message.author.tag}`,
8
{ type: 'text' }
9
);
10
await channel.setParent('912495738947260446');
11
12
// updates channel perms
13
14
channel.updateOverwrite(message.guild.id, {
15
SEND_MESSAGE: false,
16
VIEW_CHANNEL: false
17
});
18
19
channel.updateOverwrite(message.author, {
20
SEND_MESSAGE: true,
21
VIEW_CHANNEL: true
22
});
23
24
const reactionMessage = await channel.send('Thanks for opening a ticket! A staff member will be with you shortly. While you are here, please tell us why you opened this ticket.');
25
26
try {
27
await reactionMessage.react("🔒");
28
await reactionMessage.react("🗑️");
29
} catch(err) {
30
channel.send('Error sending emojis! Please tell a developer to check the console!');
31
throw err;
32
}
33
34
const collector = reactionMessage.createReactionCollector((reaction, user) => message.guild.members.cache.find((member) => member.id === user.id).hasPermission('ADMINISTRATOR'), {dispose: true});
35
36
collector.on('collect', (reaction, user) => {
37
switch (reaction.emoji.name) {
38
case "🔒":
39
channel.updateOverwrite(message.author, { SEND_MESSAGE: false, VIEW_CHANNEL: false});
40
channel.setname(`🔒 ${channel.name}`)
41
break;
42
case "🗑️":
43
channel.send('Deleting Channel in 10 seconds!');
44
setTimeout(() => channel.delete(), 10000);
45
break;
46
}
47
});
48
}
49
}
50
Advertisement
Answer
It seems you’re using discord.js v13 and trying 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:
JavaScript
1
5
1
channel.permissionOverwrites.edit(
2
message.author,
3
{ SEND_MESSAGES: false, VIEW_CHANNEL: false },
4
)
5