Tenjaou
Tenjaou
Explore posts from servers
SIASapphire - Imagine a framework
Created by Tenjaou on 6/27/2024 in #sapphire-support
error: A compatible class export was not found.
My code
import {
InteractionHandler,
InteractionHandlerTypes,
} from "@sapphire/framework";
import type { ButtonInteraction } from "discord.js";
import { client } from "../index.js";
export class ButtonHandler extends InteractionHandler {
public constructor(
ctx: InteractionHandler.LoaderContext,
options: InteractionHandler.Options
) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button,
});
}

public override async parse(interaction: ButtonInteraction) {
const buttonId = interaction.customId;
const [toDo, guildId, panelId, ticketModelId] = buttonId.split("-");
await interaction.deferReply({ ephemeral: true });
const guildData = await client.tickets.getGuild(guildId);
if (!guildData) {
{
interaction.editReply({
content: i18next.t("commands:error.unknown", {
warnEmoji: client.makeEmoji(EMOJI.WARNING),
}),
});
return this.none();
}
}
switch (toDo) {
case "ticketCreate": {
const ticketModel = guildData.ticketModels.find(
(ticketModel) =>
ticketModel.ticketModelId === parseInt(ticketModelId) &&
ticketModel.panelId === parseInt(panelId)
);
return this.some({ guildData, ticketModel });
}
default: {
return this.none();
}
}
}
public async run(
interaction: ButtonInteraction,
data: {
guildData: Prisma.GuildGetPayload<{
include: {
panels: true;
ticketModels: true;
tickets: true;
};
}>;
ticketModel: TicketModel;
}
) {
//redacted to save space
}
}
import {
InteractionHandler,
InteractionHandlerTypes,
} from "@sapphire/framework";
import type { ButtonInteraction } from "discord.js";
import { client } from "../index.js";
export class ButtonHandler extends InteractionHandler {
public constructor(
ctx: InteractionHandler.LoaderContext,
options: InteractionHandler.Options
) {
super(ctx, {
...options,
interactionHandlerType: InteractionHandlerTypes.Button,
});
}

public override async parse(interaction: ButtonInteraction) {
const buttonId = interaction.customId;
const [toDo, guildId, panelId, ticketModelId] = buttonId.split("-");
await interaction.deferReply({ ephemeral: true });
const guildData = await client.tickets.getGuild(guildId);
if (!guildData) {
{
interaction.editReply({
content: i18next.t("commands:error.unknown", {
warnEmoji: client.makeEmoji(EMOJI.WARNING),
}),
});
return this.none();
}
}
switch (toDo) {
case "ticketCreate": {
const ticketModel = guildData.ticketModels.find(
(ticketModel) =>
ticketModel.ticketModelId === parseInt(ticketModelId) &&
ticketModel.panelId === parseInt(panelId)
);
return this.some({ guildData, ticketModel });
}
default: {
return this.none();
}
}
}
public async run(
interaction: ButtonInteraction,
data: {
guildData: Prisma.GuildGetPayload<{
include: {
panels: true;
ticketModels: true;
tickets: true;
};
}>;
ticketModel: TicketModel;
}
) {
//redacted to save space
}
}
7 replies
SIASapphire - Imagine a framework
Created by Tenjaou on 6/23/2024 in #sapphire-support
Message commands help
Hey I started my journey with sapphire today and can't seem to make message command's work This is my code so far
//index.ts
import "@sapphire/plugin-i18next/register";
import { LogLevel } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import { config } from "./export.js";
import Client from "./structures/client.js";
export const client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],
fetchPrefix: async () => {
return config.PREFIX;
},
i18n: {
fetchLanguage: async () => {
return "en-US";
},
},
loadMessageCommandListeners: true,
logger: {
level: LogLevel.Debug,
},
});
client.login(config.TOKEN);
//index.ts
import "@sapphire/plugin-i18next/register";
import { LogLevel } from "@sapphire/framework";
import { GatewayIntentBits } from "discord.js";
import { config } from "./export.js";
import Client from "./structures/client.js";
export const client = new Client({
intents: [
GatewayIntentBits.MessageContent,
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
],
fetchPrefix: async () => {
return config.PREFIX;
},
i18n: {
fetchLanguage: async () => {
return "en-US";
},
},
loadMessageCommandListeners: true,
logger: {
level: LogLevel.Debug,
},
});
client.login(config.TOKEN);
//ping.ts
import { Command } from "@sapphire/framework";
import { i18next } from "@sapphire/plugin-i18next";
import type { Message } from "discord.js";

export class PingCommand extends Command {
constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
name: "ping",
aliases: ["p"],
description: "Shows the latency of the bot.",
});
}
public registerApplicationCommands(registry: Command.Registry) {
//redacted to save writing space
}

public async messageRun(message: Message) {
const time = Date.now();
const msg = await message.reply({ content: "Pinging..." });

const roundTripTime = Date.now() - time;
const wsPing = this.container.client.ws.ping;

return msg.edit(
i18next.t("commands:ping", {
roundTime: roundTripTime,
ping: wsPing.toFixed(),
})
);
}
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
//redacted to save writing space
}
}
//ping.ts
import { Command } from "@sapphire/framework";
import { i18next } from "@sapphire/plugin-i18next";
import type { Message } from "discord.js";

export class PingCommand extends Command {
constructor(context: Command.LoaderContext, options: Command.Options) {
super(context, {
...options,
name: "ping",
aliases: ["p"],
description: "Shows the latency of the bot.",
});
}
public registerApplicationCommands(registry: Command.Registry) {
//redacted to save writing space
}

public async messageRun(message: Message) {
const time = Date.now();
const msg = await message.reply({ content: "Pinging..." });

const roundTripTime = Date.now() - time;
const wsPing = this.container.client.ws.ping;

return msg.edit(
i18next.t("commands:ping", {
roundTime: roundTripTime,
ping: wsPing.toFixed(),
})
);
}
public async chatInputRun(interaction: Command.ChatInputCommandInteraction) {
//redacted to save writing space
}
}
Slash command's work but message commands doesnt seem to work
38 replies