1

I want to make a Ticket System and in the ticket when you react with ✅ makes the channel view only from admins. (Closes the ticket.)

Code:

if (reaction.emoji.name === "✅") {
    if(!reaction.message.channel.name.includes('ticket-')) return
    reaction.users.remove(user)

    reaction.message.reactions.cache.get('✅').remove()
    reaction.message.reactions.cache.get('❌').remove()

    let channel = reaction.message

    channel.updateOverwrite("user.id", { VIEW_CHANNEL: false });
}

Error: TypeError: channel.updateOverwrite is not a function

Skulaurun Mrusal
  • 2,792
  • 1
  • 15
  • 29
Red.1111
  • 25
  • 5
  • From your code it seems like `channel` is only the `message` object, not the actual `channel` object. I think you just need to switch `let channel = reaction.message` to `let channel = reaction.message.channel`. – PerplexingParadox Jul 29 '21 at 22:39

1 Answers1

1

First of all, channel is not an instance of GuildChannel but of Message, which is probably a mistake. To get the corresponding GuildChannel object, use the following: (as PerplexingParadox said in their comment.)

let channel = reaction.message.channel;

The next thing is that Collection.get() method accepts a key as its parameter, which is in this case the reaction id (or Twitter Snowflake). To find a reaction by its name, you could do this:

for (const emojiName of ["✅", "❌"]) {
    reaction.message.reactions.cache.find((reaction) => {
        return reaction.emoji.name === emojiName;
    })?.remove();
}

And remove them if they are found using the optional chaining operator.

At last GuildChannel.updateOverwrite() accepts RoleResolvable or UserResolvable as its first argument. Passing in a user's id is correct, because it falls under UserResolvable. You probably accidentally added the quotation marks around the user.id. It is a variable, if you want it to be treated like one remove the quotation marks, otherwise it will be treated as nothing more but a string with a text inside. And won't work because text "user.id" is not a valid Twitter Snowflake.

channel.updateOverwrite(user.id, { VIEW_CHANNEL: false });
Skulaurun Mrusal
  • 2,792
  • 1
  • 15
  • 29