Getting a text channel id and name

I am trying to post a welcome message when my bot join's a new server. I am trying to find a text channel where it has perms to post but my current code just returns undefined welcomeChannel = guild.channels.cache.find( (channel) => channel.type === "text" && channel.permissionsFor(guild.me).has("SEND_MESSAGES") );
17 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Febkosq8
Febkosq8OP3y ago
Febkosq8
Febkosq8OP3y ago
I have a pre defined list of channels to look for, if they are not found then i look for the system channel but however if there is not one available. then I need to find a channel where i can post the embed. Everything except the parts from 154 to 158 is working.
Squid
Squid3y ago
That code is for v12, not v14 * The "text" channel type is now ChannelType.GuildText from the enum * guild.me was replaced with guild.members.me * "SEND_MESSAGES" was replaced with PermissionFlagsBits.SendMessages
Febkosq8
Febkosq8OP3y ago
will update and let you know also where exactly in the discord js docs do i find this. I tried looking for the using keywork search but didnt find anything
Febkosq8
Febkosq8OP3y ago
That worked
Febkosq8
Febkosq8OP3y ago
How can i get channel name from channel id? i tried
Squid
Squid3y ago
Collection#get takes the collection's keys (in this case, ids) as an argument; not the channel object (welcomeChannel). In this case, there's no need to go through the cache to get the channel object since you already have it. Just access welcomeChannel.name directly
Febkosq8
Febkosq8OP3y ago
Thanks that worked. I assumed that welcomeChannel was the id specifically bcz when i console.log(welcomeChannel) it gave me the channel id not an object
Febkosq8
Febkosq8OP3y ago
Febkosq8
Febkosq8OP3y ago
line 167 i am printing welcomeChannel in console it gave me what i assumed was the id
Squid
Squid3y ago
It probably has to do with the fact you're concatenating it into a string, not logging the actual object log(a, b, c) is not the same as log(a + b + c)
Febkosq8
Febkosq8OP3y ago
makes sense. on unrelated not when i test adding my bot to new servers i keep hitting my rate limit
Febkosq8
Febkosq8OP3y ago
Febkosq8
Febkosq8OP3y ago
is there any way around
Squid
Squid3y ago
Use global commands instead of deploying guild commands in every guild
Febkosq8
Febkosq8OP3y ago
have to look that up thanks
Want results from more Discord servers?
Add your server