Says that interaction.isChatInputCommand is not a function

so this is my code
import DiscordClient from "../utils/client.ts";
import Event from "../utils/structures/Event.ts"
import { Events, Interaction } from "npm:discord.js";

export default class InteractionCreateEvent extends Event {

constructor() {
super(Events.InteractionCreate, false);
}

async execute(client: DiscordClient, interaction: Interaction): Promise<void> {

if (interaction.isChatInputCommand()) {

const command = client.commands.get(interaction.commandName);

if (!command) {
return;
}

try {
command.execute(client, interaction)
} catch (error) {
console.log(error)
}

}

}

}
import DiscordClient from "../utils/client.ts";
import Event from "../utils/structures/Event.ts"
import { Events, Interaction } from "npm:discord.js";

export default class InteractionCreateEvent extends Event {

constructor() {
super(Events.InteractionCreate, false);
}

async execute(client: DiscordClient, interaction: Interaction): Promise<void> {

if (interaction.isChatInputCommand()) {

const command = client.commands.get(interaction.commandName);

if (!command) {
return;
}

try {
command.execute(client, interaction)
} catch (error) {
console.log(error)
}

}

}

}
and when i run a command it gives this error
error: Uncaught (in promise) TypeError: interaction.isChatInputCommand is not a function
if (interaction.isChatInputCommand()) {
error: Uncaught (in promise) TypeError: interaction.isChatInputCommand is not a function
if (interaction.isChatInputCommand()) {
this is how my events are registerd. if it helps
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, args)});
}
}
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, args)});
}
}
the event class is just a simple abstract class with some values like the type of event called event and if its run once like for the ready event called once
11 Replies
d.js toolkit
d.js toolkit15mo 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!
Toast
Toast15mo ago
i think you need to use BaseInteraction instead of Interaction
Kay
KayOP15mo ago
nope. didnt fix it
Toast
Toast15mo ago
cant help with anything further then, as it should work.
Kay
KayOP15mo ago
alr thx
sicklinebro
sicklinebro15mo ago
interaction is not really an interaction then, log it and see what it is
Kay
KayOP15mo ago
uhhm. this looks like an interaction to me
sicklinebro
sicklinebro15mo ago
It's an array though
Kay
KayOP15mo ago
oh yhea would it be becouse of the way that i register the events?
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, args)});
}
}
async events(): Promise<void> {
for (const entry of walkSync(this.client.root + "\\src\\events", {includeDirs: false, exts: [".ts"]})) {
const file = await import("file://" + entry.path);
const event: Event = new file.default();
if (event.once == true) this.client.once(event.event, (...args: any[]) => {event.execute(this.client, args)});
else this.client.on(event.event, (...args: any[]) => {event.execute(this.client, args)});
}
}
sicklinebro
sicklinebro15mo ago
event.execute(this.client, ...args)
Kay
KayOP15mo ago
oh thx that worked
Want results from more Discord servers?
Add your server