Discord.JS | Getting channel object returns undefined

£可爱£侵袭症+ 提交于 2021-01-29 04:17:23

问题


I have some issues understanding the Discord.JS module, I have no clue of how to connect my bot to a server, even after looking at a lot of documentaries!

var Discord = require           ( 'discord.js' ),
    Client = new Discord.Client (              );

Client.on ( 'ready', () => {
  console.log ( Client.channels.get ( '***ChannelID***' ) );
});

Client.login ( '***TOKEN***' );


Output:

undefined


Where getting the channel returns undefined even I pass the correct id.

I don't know if the bot can connect to it without being invited to the server, and can't seem to find anything on it either?

Thanks!


回答1:


Bots must be in a server to get an ID

Example (Sorry my bot is in python but it is similar in the way it uses API):

This is because my bot is in the second channel but the first is made up



来源:https://stackoverflow.com/questions/42321485/discord-js-getting-channel-object-returns-undefined

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!