最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论