0

I have a ticket system, but it is only based on buttons. So I want to add a /close that allows me to close the channel, but I can't find a way to make it detect if the channel is called "ticket-" then transcribe it and close it.

I tried using but it does not work:

const channel = interaction.guild.channels.find(channel => channel.name === "ticket-");
zvy5
  • 3
  • 1
  • Is `ticket-` the full name, or just a part of it? If it's a part of the full name, maybe this could help: https://stackoverflow.com/questions/67431647/find-channel-using-partial-name – FiddlingAway Dec 15 '22 at 21:54

1 Answers1

0

If you are trying to find all channels that contains ticket- prefix, you can not directly compare channel.name because then you are trying to find something that fully match given value. To find a string that start with some prefix you should use .startsWith method

const someStrings = ['aaTEST', 'bbTEST', 'ccTEST', 'aaSOME'];
const onlyAA = someStrings.filter(item => item.startsWith('aa'));
console.log(onlyAA);
Krzysztof Kaczyński
  • 4,412
  • 6
  • 28
  • 51