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•3y ago
Message Not Public
Sign In & Join Server To View
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.
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
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
That worked
How can i get channel name from channel id? i tried
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
directlyThanks 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
line 167 i am printing welcomeChannel in console
it gave me what i assumed was the id
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)
makes sense.
on unrelated not when i test adding my bot to new servers
i keep hitting my rate limit
is there any way around
Use global commands instead of deploying guild commands in every guild
have to look that up thanks