Discord.js v12.0.1 频道未定义 [英] Discord.js v12.0.1 channel is undefined

查看:33
本文介绍了Discord.js v12.0.1 频道未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让机器人从 id 中读取频道名称.但是我应该为此使用正确的代码.

I'm trying to get a bot to read the name of a channel from an id. However I should be using the correct code for this.

这是我的代码:

client.channels.fetch('670722326664314911')
.then(channel => console.log(channel.name))
.catch(console.error);

错误:TypeError:无法读取 null 的属性名称"

Error: TypeError: Cannot read property 'name' of null

推荐答案

我已经运行了这段代码,没有任何问题.它返回频道的名称没有任何问题.

I have ran this code with no problems. It returns the name of the channel without any problems.

请确保机器人在公会中并且您使用正确的频道 ID.请检查机器人是否有权查看/读取给定频道.

Please make sure the bot is in the guild and you use the right channel ID. Please check if the bot has permissions to see/read the given channel.

同时检查机器人是否有任何频道:console.log(client.channels).很好的开始方式.

Also check if the bot does have any channels: console.log(client.channels). Great way to start.

这篇关于Discord.js v12.0.1 频道未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆