获取错误"TypeError: Cannot read property 'channel' of undefined"



我一直得到错误TypeError: Cannot read property 'channel' of undefined

const messageChannel = cheese.channel.cache.get("796750832305307719");

下面是我的代码:


const Discord = require('discord.js');
const { Client, Intents, Guild, channels } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });
const cron = require('node-cron');
const express = require('express');
require('dotenv').config;
const channel = require('discord.js')
const { TextChannel } = require('discord.js')
const cheese = client.guilds.cache.get("796750832305307716");
const messageChannel = cheese.channel.cache.get("796750832305307719");
try {
app = express();
cron.schedule('* 24 18 * * *', function() {
client.login('token').then(() =>{
console.log("I am ready");
messageChannel.send("TEST").then(() => client.destroy());
})     
});
app.listen(3000);

我在你的代码中发现了两个问题,所以我将从顶部开始。

错误TypeError: Cannot read property 'channel' of undefined表示对象chesse的后面是undefined。所以也许你的公会id在

const cheese = client.guilds.cache.get("796750832305307716");

是不正确的。尝试再次复制您的公会id(如果仍然是相同的id,可能您的bot不在您的目标服务器上)'

也将

中的channel改为channels
const messageChannel = cheese.channel.cache.get("796750832305307719");

你在多个频道之间搜索,所以如果我没弄错的话,它是复数

相关内容

  • 没有找到相关文章

最新更新