I get this error when running the code, my research says its something about send not being available on it or not defined, I don't fully understand it or how to fix it though.
The code:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Client, Collection, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] })
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
const channel = client.channels.cache.get('997960087249371136');
do {
sleep(1000)
let number = Math.floor(Math.random() * 5);
if(number = 1) {
channel.send("Carrier under attack!")
} else if(number = 2) {
channel.send("Carrier leak detected in lower quaters!")
} else if(number = 3) {
channel.send("All is quiet, for now.")
} else if(number = 4) {
channel.send("Unidentified aircraft entering our airspace!")
} else {
console.log("The impossible is possible!")
}
}
while(true);
I know the channels do exist.
you just created the client, you haven't logged in with your token yet, this is why "client.channels.cache" is empty and contains no channels yet. To fix this you have to put everything on the "ready" event
Also there's some other problems on your code:
const { SlashCommandBuilder } = require('@discordjs/builders');
const { Client, Collection, Intents, MessageEmbed } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] })
client.on('ready', async () =>{
const channel = client.channels.cache.get('997960087249371136');
do {
await sleep(1000)
let number = Math.floor(Math.random() * 5);
if(number == 1) return channel.send("Carrier under attack!")
else if(number == 2) return channel.send("Carrier leak detected in lower quaters!")
else if(number == 3) return channel.send("All is quiet, for now.")
else if(number == 4) return channel.send("Unidentified aircraft entering our airspace!")
else return channel.send("The impossible is possible!")
} while(true);
})
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
client.login("YOUR TOKEN")