Help with @discordjs/core - interactionCreate argument passing

Hello, So decided to use @discordjs/core. However when I went through the docs and got to the point where the interactionCreate event is being listend to like that
client.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction, api }) => {
if (interaction.type !== InteractionType.ApplicationCommand || interaction.data.name !== 'ping') {
return;
}

await api.interactions.reply(interaction.id, interaction.token, { content: 'Pong!', flags: MessageFlags.Ephemeral });
});
client.on(GatewayDispatchEvents.InteractionCreate, async ({ data: interaction, api }) => {
if (interaction.type !== InteractionType.ApplicationCommand || interaction.data.name !== 'ping') {
return;
}

await api.interactions.reply(interaction.id, interaction.token, { content: 'Pong!', flags: MessageFlags.Ephemeral });
});
I got kinda confused on how to properly translate that to my structure..
2 Replies
d.js toolkit
d.js toolkit•17mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
darby
darbyOP•17mo ago
This is my current event-Handler function to register events.
public async doRegisterEvents(client: Client): Promise<void> {
try {
for (const file of this._eventFiles) {
const eventModule = await import(join(EVENT_FILES_PATH, file));
const eventHandler: Discord.Event = eventModule.default;

// Destruct event module
const eventType = eventHandler.type;
const eventOnce = eventHandler.once;
const eventOnEmit = eventHandler.onEmit;

//TODO - Fix this dog shit 'eventType as any'
eventOnce
? client.once(eventType as any, (...args) => eventOnEmit(...args))
: client.on(eventType as any, (...args) => eventOnEmit(...args));

logger.info(
`Successfully registered event handler for event '${eventType}'`
);
}
} catch (error) {
logger.error(`Error while registering events! Error: ${error}`);
}
}
public async doRegisterEvents(client: Client): Promise<void> {
try {
for (const file of this._eventFiles) {
const eventModule = await import(join(EVENT_FILES_PATH, file));
const eventHandler: Discord.Event = eventModule.default;

// Destruct event module
const eventType = eventHandler.type;
const eventOnce = eventHandler.once;
const eventOnEmit = eventHandler.onEmit;

//TODO - Fix this dog shit 'eventType as any'
eventOnce
? client.once(eventType as any, (...args) => eventOnEmit(...args))
: client.on(eventType as any, (...args) => eventOnEmit(...args));

logger.info(
`Successfully registered event handler for event '${eventType}'`
);
}
} catch (error) {
logger.error(`Error while registering events! Error: ${error}`);
}
}
First of all I still need to figure out how to fix the error where I check if the event should be called once or not because of the spread operator.. A spread argument must either have a tuple type or be passed to a rest parameter. I don't know how to fix it yet The ready event works perfectly fine
import {GatewayDispatchEvents, Client} from '@discordjs/core';
import logger from '../utilities/logger.util';

async function doHandleReadyEvent(client: Client): Promise<void> {
client.api.users
.getCurrent()
.then(user => {
logger.info(`Bot successfully logged in! Username: ${user.username}`);
})
.catch(error => {
logger.error(`Error occured during login process! Error: ${error}`);
});
}

const readyEvent = {
type: GatewayDispatchEvents.Ready,
once: true,
onEmit: doHandleReadyEvent,
};

export default readyEvent;
import {GatewayDispatchEvents, Client} from '@discordjs/core';
import logger from '../utilities/logger.util';

async function doHandleReadyEvent(client: Client): Promise<void> {
client.api.users
.getCurrent()
.then(user => {
logger.info(`Bot successfully logged in! Username: ${user.username}`);
})
.catch(error => {
logger.error(`Error occured during login process! Error: ${error}`);
});
}

const readyEvent = {
type: GatewayDispatchEvents.Ready,
once: true,
onEmit: doHandleReadyEvent,
};

export default readyEvent;
But now I ask myself how do I get this to work for the interactionCreate event This is my type for the event
export interface Event {
type: string;
once: boolean;
onEmit: (...args: any[]) => Promise<void>;
}
export interface Event {
type: string;
once: boolean;
onEmit: (...args: any[]) => Promise<void>;
}
For the type I think I fixed it . see edit Uh like this? ```ts export interface Event { type: keyof ManagerShardEventsMap; once: boolean; onEmit: (...args: any[]) => Promise<void>; }``` Oh alright that's good to know Well yep I guess I have to use WebSocketShardEvents.Ready then ? Atleast this is what I have done now ```ts async function doHandleReadyEvent(client: Client): Promise<void> { client.api.users .getCurrent() .then(user => { logger.info(Bot successfully logged in! Username: ${user.username}); }) .catch(error => { logger.error(Error occured during login process! Error: ${error}`); }); } const readyEvent: Discord.Event<WebSocketShardEvents.Ready> = { type: WebSocketShardEvents.Ready, once: true, onEmit: doHandleReadyEvent, }; ``` I do need to change the onEmit because of the params with client Uhmm okay.. well the whole WebSocket thing is kinda new to me.. guess I gotta need way more time 😅 Or atleast saying the /core package Well.. I went to the discordjs site and clicked on docs to see what is new since it's a bit since I wrote a bot.. so there I just saw that it said you need to npm i @discordjs/core So I assumed this is new go to But I guess not haha Ohhh okay 😄 I really thought it's the new way 😅 Well I guess I am better of with using the mainlib for now
Want results from more Discord servers?
Add your server