Comments (6)
I've looked at your example implementation - it's a little confusing to read due to the number of completely unnecessary changes away from async functions. If I'm interpreting it correctly, it would appear that the developer still has to manually call deferReply, but then discord.js would be responsible for awaiting it internally?
This could be considered over-opinionated code - it should remain up to the developer to implement rather than abstracted away inside a library where they have no control. Given that the implementation on the developer's side is a single await
keyword rather than... whatever this is, I don't think we'll be adding this feature.
from discord.js.
a single
await
keyword
yeah, there's a lot of examples look like this:
await interaction.deferReply();
await asyncOperation();
interaction.followUp("message");
yes, that's a single await
keyword. but let's assume that deferReply takes t1
of time, and asyncOperation takes t2
of time, then the example above will take t1 + t2
of time, and i don't like that.
to make it take max(t1, t2)
of time, the implementation would be:
const defer = interaction.deferReply();
await asyncOperation();
await defer;
interaction.followUp("message");
or
const operation = asyncOperation();
await interaction.deferReply();
await operation;
interaction.followUp("message");
or
await Promise.all([interaction.deferReply(), asyncOperation()]);
interaction.followUp("message");
now the code looks a bit complicated than before, which i think it's unnecessary to do that everywhere (reduce repetitive code), so i already made a mixin for it for myself, then my code will be cleaner:
interaction.deferReply();
await asyncOperation();
interaction.followUp("message");
and i thought it would be great to just implement it on d.js.
or maybe... add an option in ClientOptions
called awaitForDefer
if it's too over-opinionated, i still think it would be a good feature.
from discord.js.
All of your examples ignore both the order of execution and individual successful execution - which is fine if you don't care. However, they carry the risk that you will defer without the asyncOperation completing successfully, or execute an asyncOperation without the defer completing successfully.
You're welcome to manage this in your own code where you have the control to do so, as vlad suggested. Taking that design choice away from the developer and putting it inside the library would be bad practice.
Making your code "cleaner" does not make it better.
from discord.js.
Can you explain a bit more what you mean by this? do you have any use cases for this change?
from discord.js.
This sounds like something you could implement yourself in a utility function, and not something the library should be responsible for doing 👀
from discord.js.
Understood. Thanks for the explanations!
from discord.js.
Related Issues (20)
- Slash command builder type incompatibility HOT 4
- Poll not being created on slash command interaction HOT 4
- `ActionRowBuilder<T>` does not enforce the type of the components to be `T` HOT 1
- Include which users answered what on the finished polls on the payload HOT 2
- Cannot use module due to version upgrading HOT 2
- Ban Appeal
- addChoices in RoleSelectMenuBuilder or in addRoleOption (SlashCommandRoleOption) HOT 1
- Redis ReplyError when pulling with xreadgroup on empty subscribed events HOT 2
- Add `reason` to follow announcement channel endpoint
- Have event handler callbacks support both async/sync methods HOT 3
- No definition found for the 'commands' property HOT 1
- Ambiguous event names: LinkTags and Anchors
- Only messages are allowed to create polls HOT 1
- Merged interfaces from package overview 404.
- Inaccurate typings for GuildMember#partial
- `Message#fetchReference()` returns a non-message on certain message types
- @discordjs/voice not working with Bun HOT 1
- fix MessagePayload.js to send voice message
- TypeError in GuildDeleteAction.handle when Destroying Voice Adapter HOT 13
- Bot send embed messages twice or even triple times after being not used for a while HOT 15
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.