#Fetching Channels v13

16 messages · Page 1 of 1 (latest)

stone sleet
#

Hey , guys im trying to fetch all text channels in a guild with a specific name.
so at first i just use

    const Channels = await interaction.guild.channels.fetch();
    console.log(Channels);

which show all the channels in guild perfectly.
for the next step that i wanna filter to get text channels only with a specific name i dont get the right thing ( or at least i think so).

const OrganizerEmoji = Array.from(Organizer.nickname)[0];
const TextChannels = Channels.map((c) => c.type === 'GUILD_TEXT' && c.name.includes(`${OrganizerEmoji}`));
console.log(TextChannels);

and the respond i get is

[
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false, false, false, false, false,
  false, false, false, false,
  ... 198 more items
]
mental spadeBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

stone sleet
mighty veldt
#

v13 already supports modals so discord-modals is unnecessary

#

you also don’t need to fetch channels if you have the GUILDS intent unless it’s a thread

#

you may also want to update to v13.15.1

mighty veldt
#

for getting the channels with a specific name, you should use .filter instead of .map

wicked jungleBOT
#
const channel = client.channels.cache.get("222086648706498562");
const channel = guild.channels.cache.find(channel => channel.name === "general");

• Caches in discord.js are Collections which extend the native Map structure.
learn more

mighty veldt
#

find is also an option, but filter is probably better

stone sleet
stone sleet
mighty veldt
#

that’s great

#

mapping isn’t really meant to serve as a filter

#

it’s meant to well … create a new array populated with the results of calling a provided function on every element in the calling array

stone sleet