javascript - Problem with client.channels.get();client.channels.find(); - Stack Overflow

I have been working on a discord bot and I want to send a message as soon as it gets online in a set an

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.

Share Improve this question edited Apr 22, 2020 at 14:47 matthias_h 11.4k9 gold badges23 silver badges40 bronze badges asked Apr 22, 2020 at 10:15 H3tRH3tR 231 silver badge8 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 2

In 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条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信