TheeDeer
Explore posts from serversSIASapphire - Imagine a framework
•Created by TheeDeer on 8/11/2024 in #sapphire-support
Type Error: "Property "sentryError" does not exist on type 'ILogger'
Ive extended the
SentryClient.TS
Reduced code for clarity
Usage:
Error:
https://i.imgur.com/PrA4R7b.png
@sapphire/plugin-logger
to add sentry logging, however it is still throwing type errors when I try to use said functions.
SentinelLogger.ts
import { container } from '@sapphire/framework';
import { Logger } from '@sapphire/plugin-logger';
import { captureException, captureMessage, Scope } from '@sentry/node';
import { redBright } from 'colorette';
export class SentinelLogger extends Logger {
public infoTag(tag: string, value: unknown): void {
super.info(`[${redBright(tag)}] ${value}`);
}
public sentryMessage(message: string, context?: NonNullable<unknown>): void {
super.error(message);
if (container.isDev) return;
captureMessage(message, (scope): Scope => {
if (context) scope.setExtra('context', context);
return scope;
});
}
public sentryError(error: unknown, { message, context }: { message?: string; context?: NonNullable<unknown> } = {}): void {
message ? super.error(message) : super.error(error);
if (container.isDev) return;
if (error instanceof Error) {
captureException(error, (scope): Scope => {
if (context) scope.setExtras(context);
return scope;
});
}
}
}
import { container } from '@sapphire/framework';
import { Logger } from '@sapphire/plugin-logger';
import { captureException, captureMessage, Scope } from '@sentry/node';
import { redBright } from 'colorette';
export class SentinelLogger extends Logger {
public infoTag(tag: string, value: unknown): void {
super.info(`[${redBright(tag)}] ${value}`);
}
public sentryMessage(message: string, context?: NonNullable<unknown>): void {
super.error(message);
if (container.isDev) return;
captureMessage(message, (scope): Scope => {
if (context) scope.setExtra('context', context);
return scope;
});
}
public sentryError(error: unknown, { message, context }: { message?: string; context?: NonNullable<unknown> } = {}): void {
message ? super.error(message) : super.error(error);
if (container.isDev) return;
if (error instanceof Error) {
captureException(error, (scope): Scope => {
if (context) scope.setExtras(context);
return scope;
});
}
}
}
export class SentinelClient extends SapphireClient {
public constructor() {
super({
logger: {
instance: new SentinelLogger({ level: LogLevel.Debug, join: '\n' })
}
});
}
}
export class SentinelClient extends SapphireClient {
public constructor() {
super({
logger: {
instance: new SentinelLogger({ level: LogLevel.Debug, join: '\n' })
}
});
}
}
@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError
})
export class ErrorListener extends Listener<typeof Events.CommandApplicationCommandRegistryError> {
public run(error: Error, command: Command): void {
const { name, location } = command;
this.container.logger.sentryError(error, {
message: `Encountered error while handling the command application command registry for ${name} (${location.full})`,
context: command
});
}
}
@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError
})
export class ErrorListener extends Listener<typeof Events.CommandApplicationCommandRegistryError> {
public run(error: Error, command: Command): void {
const { name, location } = command;
this.container.logger.sentryError(error, {
message: `Encountered error while handling the command application command registry for ${name} (${location.full})`,
context: command
});
}
}
12 replies
SIASapphire - Imagine a framework
•Created by TheeDeer on 2/5/2024 in #sapphire-support
Commands + Listeners not registering
My commands and listeners are not registering/running. I suspect its because I'm using tsx but am not sure what the best way to resolve it would be
9 replies
SIASapphire - Imagine a framework
•Created by TheeDeer on 6/25/2023 in #sapphire-support
Modal Validation Error
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework')
const { ModalBuilder, TextInputStyle, TextInputBuilder, ActionRowBuilder } = require('discord.js')
module.exports = class extends InteractionHandler {
constructor (ctx) {
super(ctx,
{
interactionHandlerType: InteractionHandlerTypes.SelectMenu
}
)
}
async parse (interaction) {
if (interaction.customId !== 'department' && interaction.customId !== 'staff') return this.none()
return this.some()
}
async run (interaction, result) {
try {
const selected = interaction.values[0]
const modal = new ModalBuilder()
modal.setCustomId(`ticketSubmit_${selected}`)
if (selected === 'inquiry') {
const textInput = new TextInputBuilder()
textInput.setCustomId('inputOne')
textInput.setLabel('What is your question?')
textInput.setStyle(TextInputStyle.Paragraph)
const actionRow = new ActionRowBuilder().addComponents(textInput)
modal.addComponents(actionRow)
} else if (selected === 'report') {
const reportWho = new TextInputBuilder()
reportWho.setCustomId('inputOne')
reportWho.setLabel('Who are you reporting')
reportWho.setStyle(TextInputStyle.Short)
const textInput = new TextInputBuilder()
textInput.setCustomId('inputTwo')
textInput.setLabel('Why are you reporting this individual?')
textInput.setStyle(TextInputStyle.Paragraph)
const actionRow = new ActionRowBuilder().addComponents(reportWho)
const secondActionRow = new ActionRowBuilder().addComponents(textInput)
modal.addComponents(actionRow, secondActionRow)
}
await interaction.showModal(modal)
} catch (err) {
console.error(err)
}
}
}
const { InteractionHandler, InteractionHandlerTypes } = require('@sapphire/framework')
const { ModalBuilder, TextInputStyle, TextInputBuilder, ActionRowBuilder } = require('discord.js')
module.exports = class extends InteractionHandler {
constructor (ctx) {
super(ctx,
{
interactionHandlerType: InteractionHandlerTypes.SelectMenu
}
)
}
async parse (interaction) {
if (interaction.customId !== 'department' && interaction.customId !== 'staff') return this.none()
return this.some()
}
async run (interaction, result) {
try {
const selected = interaction.values[0]
const modal = new ModalBuilder()
modal.setCustomId(`ticketSubmit_${selected}`)
if (selected === 'inquiry') {
const textInput = new TextInputBuilder()
textInput.setCustomId('inputOne')
textInput.setLabel('What is your question?')
textInput.setStyle(TextInputStyle.Paragraph)
const actionRow = new ActionRowBuilder().addComponents(textInput)
modal.addComponents(actionRow)
} else if (selected === 'report') {
const reportWho = new TextInputBuilder()
reportWho.setCustomId('inputOne')
reportWho.setLabel('Who are you reporting')
reportWho.setStyle(TextInputStyle.Short)
const textInput = new TextInputBuilder()
textInput.setCustomId('inputTwo')
textInput.setLabel('Why are you reporting this individual?')
textInput.setStyle(TextInputStyle.Paragraph)
const actionRow = new ActionRowBuilder().addComponents(reportWho)
const secondActionRow = new ActionRowBuilder().addComponents(textInput)
modal.addComponents(actionRow, secondActionRow)
}
await interaction.showModal(modal)
} catch (err) {
console.error(err)
}
}
}
8 replies