I have been working on a discord bot and I want to send a message as soon as it gets online in a set announcement channel. I think I know how to make it work but I keep getting the same problem. I've read several articles but they don't solve the problem I have client.channels.get is not a function
.
I don't just want to change it to a channel Id as I want it to be possible to be used on other servers than mine. I am a newbie in discord API and coding in general. That is why I don't use too advanced coding as I want to learn what it does instead of copying something I don't understand.
Thanks.
I have been working on a discord bot and I want to send a message as soon as it gets online in a set announcement channel. I think I know how to make it work but I keep getting the same problem. I've read several articles but they don't solve the problem I have client.channels.get is not a function
.
I don't just want to change it to a channel Id as I want it to be possible to be used on other servers than mine. I am a newbie in discord API and coding in general. That is why I don't use too advanced coding as I want to learn what it does instead of copying something I don't understand.
Thanks.
2 Answers
Reset to default 2In order to get any properties from the client
object, it needs to be loaded from within an event. Say for example inside the ready
event, i.e. when the bot is fully loaded, you can then do client.channels.cache.find(channel => channel.name == "name_of_channel")
, etc. To listen to an event, you do client.on("event_name_here", (parameters) => {})
.
To view a list of events, take a look at: https://discord.js/#/docs/main/stable/class/Client
If this didn't help, please post your code so we can properly determine the issue.
Since discord.js v12 you now need to use .cache
to access channels
collection.
Use client.channels.cache.get()
or client.channels.cache.find(channel => channel.name === 'Test')
instead.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745136135a4613207.html
评论列表(0条)