Comments (3)
They do support that. The issue is within your linter config here disallowing something thatβs perfectly valid typescript. See https://www.typescriptlang.org/docs/handbook/2/functions.html#return-type-void
See #10017 for details on why this was changed.
from discord.js.
Hi! This rule serves in spotting plenty of difficult bugs to deal with. In this case, when a callback is typed with an expected return type of void, it implies that, if a Promise were to be returned, it wouldn't be awaited, which is absolutely correct. The event handling in discord.js is standard EventEmitter (in some subpackages Vlad's async emitters).
One side effect you may not be aware of, is that multiple callback calls can be in effect in parallel. Think of this (pseudo-code) web example:
let someState;
htmlElement.on('click', async () => {
someState = await someAsyncFetchCall();
});
This is a disaster! If the user clicks multiple times on the button, the JS engine leaves each invocation waiting for the hypothetical HTTP call to end, and it's possible they finish in an order different than 1->2->3, causing broken state in your application.
If you find it hard to envision how this affects a Discord bot, it generally does not. One case I can think of is when you build "UX" using buttons and dropdowns, naively assigning event handlers to your collectors means I can break your implementation by just clicking a bunch of stuff in quick succession.
To summarize, us changing the type is not only incorrect from a typing perspective (because the return type of a callback first and firemost implies what we do with the return type, and the absence of Promise means we leave them dangling), but it's also bad in the context of this rule.
My personal recommendation is to leave it enabled globally, and whenever you find it erroring think twice if you're gonna be running state updates in the callback that depend on previous invocations. If not, disable it for that line.
from discord.js.
Fair enough. Thank you to both of you. I did manage to find another solution that resolves the lint error AND looks good. I'll put it here for anyone who finds this issue thread in the future.
// Set the client application commands and then exit the client
async function deployCommands(c: Client<true>) {
await c.application.commands.set(commands);
await c.destroy();
}
client.once('ready', c => void deployCommands(c));
Moving the logic into a separate method and using the void
keyword explicitly ignores whether the Promise is fulfilled, which tells @typescript-eslint
that it is intentional.
This way, I don't need to use eslint-disable-next-line
, promise chaining, or an async IIFE method wrapper.
from discord.js.
Related Issues (20)
- Client is not receiving 'messageCreate' events HOT 1
- .toJSON() is 'unknown' HOT 1
- crashing after message deletion HOT 5
- Using channel.send on a channel where the bot has not the permission to post makes the whole program crash HOT 3
- Kicking the bot from its dev guild and inviting it again drops the slash commands HOT 6
- Automated Message nonce handling HOT 1
- Emit poll events on uncached messages
- `ws` throws `TypeError: Cannot use 'in' operator to search for 'code' in undefined` when with Deno HOT 6
- Wrong base URL for GIF stickers
- [Typing] `interaction.followUp()` should not have `ephemeral` in its options? HOT 6
- oops HOT 1
- Uncaught exception when adding member that is already part of the guild
- Readonly arrays in interfaces don't allow dynamically adding data
- Allow InteractionOptionResolvers to return the raw value for different option types (like user) HOT 4
- DiscordAPIError[10062]: Unknown interaction (AutoComplete) HOT 1
- Cannot add user option when using localizations HOT 3
- Bot can't enter the ready state in voice channels
- New Premium Button Style & Deep Linking URL Schemes HOT 2
- Conflict between discord.js + @nodes/types after upgrading HOT 12
- ws affected by a DoS when handling a request with many HTTP headers HOT 1
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 discord.js.