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