Giter VIP home page Giter VIP logo

Comments (5)

NedcloarBR avatar NedcloarBR commented on May 23, 2024

Hello! you can create a Exception Filter passaing the DiscordAPIError in the @Catch decorator
You can ignore specific errors by checking it's code from RESTJSONErrorCodes that can be imported from discord-api-types

from necord.

SocketSomeone avatar SocketSomeone commented on May 23, 2024

@carlonicora Thank you for question!
@NedcloarBR right! Just read more about Exception Filters and global providers

from necord.

carlonicora avatar carlonicora commented on May 23, 2024

@NedcloarBR thanks for the reply.
I have one additional question.

I have created a specific exception filter which traps the call; however I have two issues:

  1. If I trap a DiscordAPIError, I cannot find the interaction context, hence I cannot reply to the interaction with an error.
  2. If the error is because the server still has an old slash command (not sure why the old ones are not removed), the error is not in a command, hence I cannot use the UseFilters decorator and the application crashes

Am I doing something wrong in here, or are these two edge cases?

import { Catch, ExceptionFilter } from '@nestjs/common';
import { DiscordAPIError } from 'discord.js';

@Catch(DiscordAPIError)
export class DiscordExceptionFilter implements ExceptionFilter {
  catch(error: DiscordAPIError) {
    console.log(error);

//I normally create an error embed and return it to Discord to warn the user
    // return new EmbedBuilder()
    //   .setColor(Colour.Red)
    //   .setTitle('Error')
    //   .setDescription(error.message);
  }
}

@CharacterCommandsDecorator()
@UseFilters(DiscordExceptionFilter)
export class CharacterDetailsCommand {
  @Subcommand({
    name: 'details',
    description: 'Get the details of a character',
  })
  public async onDetails(
    @Context() [interaction]: SlashCommandContext,
    @Options() { player }: ...

thanks

EDIT: forgot to add I have this

app.useGlobalFilters(new DiscordExceptionFilter());

in my main.ts

EDIT 2: I realised one of my issues: I can create a filter for my own error type to fix the issue 2, but issue 1 is still there

from necord.

SocketSomeone avatar SocketSomeone commented on May 23, 2024

@carlonicora

If I trap a DiscordAPIError, I cannot find the interaction context, hence I cannot reply to the interaction with an error.

You can get host arguments.
image
Also, you can join to our Discord server for quick response

Discord message with response

from necord.

SocketSomeone avatar SocketSomeone commented on May 23, 2024

Btw, from arguments host you can get discovery item to create own typeguard of commands, events, modals and etc.

from necord.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.