本文介绍了Discord.JS获取通道对象返回未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使在看了很多纪录片之后,我仍然在理解Discord.JS模块时遇到一些问题,甚至不知道如何将我的机器人连接到服务器!

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***' );


输出:

undefined


即使我传递了正确的ID,获取频道的地方也会返回 undefined .

我不知道机器人是否可以在不被邀请到服务器的情况下连接到它,并且似乎也找不到任何东西?

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?

谢谢!

推荐答案

机器人必须在服务器中才能获得ID

Bots must be in a server to get an ID

示例(对不起,我的机器人在python中使用,但使用API​​的方式与此类似):

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

这篇关于Discord.JS获取通道对象返回未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 05:59