Javascript Discord.js无法读取属性';获取';未定义的

Javascript Discord.js无法读取属性';获取';未定义的,javascript,node.js,discord.js,Javascript,Node.js,Discord.js,几天前,我刚开始使用Javascript和Discord.js进行开发,出现以下错误: TypeError:无法读取未定义的属性“fetch” 我正在尝试执行轮询命令。这是代码(我删除了所有其他内容,只是想让它退出频道): 我已经试着把它放在Main.js中,它可以工作: client.on('message', message => { if (message.content.startsWith('.poll')) { client.channels.fetch('74

几天前,我刚开始使用Javascript和Discord.js进行开发,出现以下错误:

TypeError:无法读取未定义的属性“fetch”

我正在尝试执行轮询命令。这是代码(我删除了所有其他内容,只是想让它退出频道):

我已经试着把它放在Main.js中,它可以工作:

client.on('message', message => {
if (message.content.startsWith('.poll')) {
        client.channels.fetch('744582158324072468')
        .then (channel => console.log(channel.name))
        .catch(console.error); 
    }
}
但是我想要正确的文件。这是我在客户端上面的内容。on('message',等等

const fs = require('fs');
const Discord = require('discord.js');
const { prefix, token, tprefix, welcomechannel, guildID } = require('./config.json');

const client = new Discord.Client({
    fetchAllMembers: true,
});

client.commands = new Discord.Collection();


const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}

const cooldowns = new Discord.Collection();

// update

client.once('ready', () => {
    console.log(`${tprefix}Paperbot got geupdated.`);
});

当然,我在谷歌上到处搜索并阅读了文档,但那没有帮助


正如我所说,我是编程新手,这可能是一个很容易解决的问题,但我希望尽快解决这个问题,非常感谢。

您可以在代码顶部为客户机分配一个新的Discord集合

您实际上是在执行
Collection.channels.fetch
而不是
client.channels.fetch


您需要将客户端从主文件传递到命令。

解决了这个问题。我只需要将消息添加到
client.channels.fetch

现在它正在使用以下代码:

const { tprefix, pollchannel, modchannel } = require('../config.json');


 module.exports = {
    name: 'poll',
    description: 'can make polls',
    cooldown: 5,
    usage: '[ask] [emoji1] [emoji 2]',
    aliases: ['createpoll'],
    execute(message) {
        message.client.channels.fetch('744582158324072468')
        .then (channel => console.log(channel.name))
        .catch(console.error);
    },
};     

谢谢@Jack Towns

现在我收到了以下消息:
HTTPError[DiscordjsError]:请求使用令牌,但客户端无法使用令牌。
@centrix.js这很可能意味着您的令牌无效,请尝试在开发面板上重新生成它。如果有人的答案解决了您的问题,请
const { tprefix, pollchannel, modchannel } = require('../config.json');


 module.exports = {
    name: 'poll',
    description: 'can make polls',
    cooldown: 5,
    usage: '[ask] [emoji1] [emoji 2]',
    aliases: ['createpoll'],
    execute(message) {
        message.client.channels.fetch('744582158324072468')
        .then (channel => console.log(channel.name))
        .catch(console.error);
    },
};