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 toolkit14mo 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
Toast14mo ago
i think you need to use BaseInteraction instead of Interaction
Kay
KayOP14mo ago
nope. didnt fix it
Toast
Toast14mo ago
cant help with anything further then, as it should work.
Kay
KayOP14mo ago
alr thx
sicklinebro
sicklinebro14mo ago
interaction is not really an interaction then, log it and see what it is
Kay
KayOP14mo ago
uhhm. this looks like an interaction to me
sicklinebro
sicklinebro14mo ago
It's an array though
Kay
KayOP14mo 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
sicklinebro14mo ago
event.execute(this.client, ...args)
Kay
KayOP14mo ago
oh thx that worked
Want results from more Discord servers?
Add your server