I've been at this for hours. Invalid Channels?

This is how im defining channels
export let channels: { paidJob: discord.Channel | null | undefined; commissionJob: discord.Channel | null | undefined; forHireJob: discord.Channel | null | undefined; unpaidJob: discord.Channel | null | undefined; vipJob: discord.Channel | null | undefined };
for (const file of commandFiles) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const command: Command = require(`./commands/${file}`);

if(!command.data || !command.execute) {
console.log(`Command ${file} is invalid. Skipping`);
break
}

console.log(`Loaded command\t${command.data.name}\t${JSON.stringify(command.options)}`)

client.commands.set(command.data.name, command);
}
client.on('interactionCreate', async interaction => {
channels.paidJob = client.channels.cache.get(channelIds.paidJob)
channels.commissionJob = client.channels.cache.get(channelIds.commissionJob)
channels.forHireJob = client.channels.cache.get(channelIds.forHireJob)
channels.unpaidJob = client.channels.cache.get(channelIds.unpaidJob)
channels.vipJob = client.channels.cache.get(channelIds.vipJob)
// Handlers
export let channels: { paidJob: discord.Channel | null | undefined; commissionJob: discord.Channel | null | undefined; forHireJob: discord.Channel | null | undefined; unpaidJob: discord.Channel | null | undefined; vipJob: discord.Channel | null | undefined };
for (const file of commandFiles) {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const command: Command = require(`./commands/${file}`);

if(!command.data || !command.execute) {
console.log(`Command ${file} is invalid. Skipping`);
break
}

console.log(`Loaded command\t${command.data.name}\t${JSON.stringify(command.options)}`)

client.commands.set(command.data.name, command);
}
client.on('interactionCreate', async interaction => {
channels.paidJob = client.channels.cache.get(channelIds.paidJob)
channels.commissionJob = client.channels.cache.get(channelIds.commissionJob)
channels.forHireJob = client.channels.cache.get(channelIds.forHireJob)
channels.unpaidJob = client.channels.cache.get(channelIds.unpaidJob)
channels.vipJob = client.channels.cache.get(channelIds.vipJob)
// Handlers
for some reason my command use.ts is invalid? its all due to this line
const embed = await addPost(job, interaction.user.id, hasRole || false)
const embed = await addPost(job, interaction.user.id, hasRole || false)
Below is the function file. The error occurs due to me assigning to the channel variable.
4 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Ateeb Sohail
Ateeb SohailOP11mo ago
import dotenv from 'dotenv'
import { Post } from './types'
import { channels } from '..'
import { Channel, TextChannel } from 'discord.js'
import { PostEmbed } from './embeds'
import { COMMISSION_JOB_BANNER_URL, FOR_HIRE_BANNER_URL, INVISIBLE_CHARACTER, PAID_JOB_BANNER_URL, PERSON_EMOJI, PERSON_PREMIUM_EMOJI, PREMIUM_COMMISSION_JOB_BANNER_URL, PREMIUM_FOR_HIRE_BANNER_URL, PREMIUM_PAID_JOB_BANNER_URL, PREMIUM_UNPAID_JOB_BANNER_URL, PREMIUM_VIP_HIRING_BANNER_URL, UNPAID_JOB_BANNER_URL } from './data'
import { mongoClient } from './mongo'
dotenv.config()

export const db = mongoClient.db("JHM")

export const collections = {
posts: db.collection('Posts'),
users: db.collection('Users'),
messages: db.collection('Messages')
}

export async function addPost(post: Post, userId: string, premium: boolean) {
let channel: Channel | undefined | null = channels.paidJob
let imgUri = ''
let color = 0x2278ff
if(premium) color = 0xd6af33
switch(post.jobType) {
case 1:
channel = channels.paidJob
if(premium) {
imgUri = PREMIUM_PAID_JOB_BANNER_URL
} else {
imgUri = PAID_JOB_BANNER_URL
}
break;
import dotenv from 'dotenv'
import { Post } from './types'
import { channels } from '..'
import { Channel, TextChannel } from 'discord.js'
import { PostEmbed } from './embeds'
import { COMMISSION_JOB_BANNER_URL, FOR_HIRE_BANNER_URL, INVISIBLE_CHARACTER, PAID_JOB_BANNER_URL, PERSON_EMOJI, PERSON_PREMIUM_EMOJI, PREMIUM_COMMISSION_JOB_BANNER_URL, PREMIUM_FOR_HIRE_BANNER_URL, PREMIUM_PAID_JOB_BANNER_URL, PREMIUM_UNPAID_JOB_BANNER_URL, PREMIUM_VIP_HIRING_BANNER_URL, UNPAID_JOB_BANNER_URL } from './data'
import { mongoClient } from './mongo'
dotenv.config()

export const db = mongoClient.db("JHM")

export const collections = {
posts: db.collection('Posts'),
users: db.collection('Users'),
messages: db.collection('Messages')
}

export async function addPost(post: Post, userId: string, premium: boolean) {
let channel: Channel | undefined | null = channels.paidJob
let imgUri = ''
let color = 0x2278ff
if(premium) color = 0xd6af33
switch(post.jobType) {
case 1:
channel = channels.paidJob
if(premium) {
imgUri = PREMIUM_PAID_JOB_BANNER_URL
} else {
imgUri = PAID_JOB_BANNER_URL
}
break;
case 2:
channel = channels.commissionJob
if(premium) {
imgUri = COMMISSION_JOB_BANNER_URL
} else {
imgUri = PREMIUM_COMMISSION_JOB_BANNER_URL
}
break;
case 3:
channel = channels.forHireJob
if(premium) {
imgUri = FOR_HIRE_BANNER_URL
} else {
imgUri = PREMIUM_FOR_HIRE_BANNER_URL
}
break;
case 4:
channel = channels.unpaidJob
if(premium) {
imgUri = UNPAID_JOB_BANNER_URL
} else {
imgUri = PREMIUM_UNPAID_JOB_BANNER_URL
}
break;
case 5:
channel = channels.vipJob
if(premium) {
imgUri = PREMIUM_PAID_JOB_BANNER_URL
} else {
imgUri = ''
}
break;
}
if(channel) {
if(post.jobType !== 4) {
const embed = new PostEmbed(
`${INVISIBLE_CHARACTER}${premium ? PERSON_PREMIUM_EMOJI : PERSON_EMOJI} ${post.jobTitle}`,
`Hi`,
color,
imgUri,
);
(channel as TextChannel).send({embeds: [embed]})
}
}
return
}
case 2:
channel = channels.commissionJob
if(premium) {
imgUri = COMMISSION_JOB_BANNER_URL
} else {
imgUri = PREMIUM_COMMISSION_JOB_BANNER_URL
}
break;
case 3:
channel = channels.forHireJob
if(premium) {
imgUri = FOR_HIRE_BANNER_URL
} else {
imgUri = PREMIUM_FOR_HIRE_BANNER_URL
}
break;
case 4:
channel = channels.unpaidJob
if(premium) {
imgUri = UNPAID_JOB_BANNER_URL
} else {
imgUri = PREMIUM_UNPAID_JOB_BANNER_URL
}
break;
case 5:
channel = channels.vipJob
if(premium) {
imgUri = PREMIUM_PAID_JOB_BANNER_URL
} else {
imgUri = ''
}
break;
}
if(channel) {
if(post.jobType !== 4) {
const embed = new PostEmbed(
`${INVISIBLE_CHARACTER}${premium ? PERSON_PREMIUM_EMOJI : PERSON_EMOJI} ${post.jobTitle}`,
`Hi`,
color,
imgUri,
);
(channel as TextChannel).send({embeds: [embed]})
}
}
return
}
heres the full command file
Ateeb Sohail
Ateeb SohailOP11mo ago
Pastebin
import { InfoEmbed } from '../modules/embeds';import { SlashCommand...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
monbrey
monbrey11mo ago
What error are you getting exactly? Im seeing a lot of code here but I'm actually not sure what the issue is When you say invalid channels is it a Discord API error, or what exactly? Or is it just that you're trying to export them before theyre defined, is that it?
Want results from more Discord servers?
Add your server