Comments (5)
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.
@carlonicora Thank you for question!
@NedcloarBR right! Just read more about Exception Filters and global providers
from necord.
@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:
- If I trap a DiscordAPIError, I cannot find the interaction context, hence I cannot reply to the interaction with an error.
- 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.
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.
Also, you can join to our Discord server for quick response
from necord.
Btw, from arguments host you can get discovery item to create own typeguard of commands, events, modals and etc.
from necord.
Related Issues (20)
- Regex and dynamic matching support for Button HOT 5
- Get the discordjs client instance HOT 3
- Dynamic matching for Modals HOT 1
- Support for NestJS v9 HOT 1
- Update the documentation to include sharding. HOT 2
- How to test ? HOT 2
- Not resolving /interactions route HOT 2
- Collectors HOT 3
- Add methods for discovery metadata HOT 1
- how can i add multiple bots within the same NestJs App HOT 2
- The `guilds` property is broken at all commands HOT 2
- Add sharding usage examples for discord-hybrid-sharding and discord-cross-hosting to docs HOT 2
- Clean up non-existing guild commands when using `guilds` property HOT 2
- Integrate new discovery decorator HOT 1
- Group commands overwriting instead of grouping HOT 2
- how to use send message to channels HOT 6
- defaultMemberPermissions does not work on Subcommand but is typed HOT 4
- Options from slash command are undefined if you use TypeORM HOT 2
- User and Emoji Providers is null or empty HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from necord.