TheeDeer
TheeDeer
Explore posts from servers
SIASapphire - 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 @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;
});
}
}
}
SentryClient.TS
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' })
}
});
}
}
Reduced code for clarity Usage:
@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
});
}
}
Error: https://i.imgur.com/PrA4R7b.png
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
DIAdiscord.js - Imagine a boo! 👻
Created by TheeDeer on 8/25/2023 in #djs-questions
Interaction/Button question
I have a quick question regarding interactions/buttons; If I post an embed with a button attached to it using Bot A, can Bot B listen for that button interaction (being clicked) and process it?
5 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)
}
}
}
https://i.imgur.com/GAhgd7l.png
8 replies