Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types: Inference of guild in MessageManager #8538

Merged
merged 3 commits into from Aug 22, 2022

Conversation

Jiralite
Copy link
Member

Please describe the changes this PR makes and why it should be merged:
Consider this:

import { Client, Events } from "discord.js";

declare const client: Client;

client.on(Events.MessageCreate, async message => {
  // Ensure we receive messages only from guilds.
  if (!message.inGuild()) return;

  message; // Type is now Message<true> & Message<boolean>.

  const sentMessage = await message.channel.send("why hello there");

  sentMessage; // Type is Message<boolean>.

  if (sentMessage.inGuild()) {
    sentMessage; // Type is now Message<true> & Message<boolean>.
  }
});

There is no way sentMessage could be from a direct message channel. This is a bit of a nuisance, so the typings have been adjusted to ensure MessageManager knows whether it is in a guild or not. With this pull request, sentMessage will be Message<true>.

Status and versioning classification:

  • Code changes have been tested against the Discord API, or there are no code changes
  • I know how to update typings and have done so, or typings don't need updating

@vercel
Copy link

vercel bot commented Aug 21, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
discord-js ✅ Ready (Inspect) Visit Preview Aug 22, 2022 at 8:28AM (UTC)

@Jiralite Jiralite changed the title types: better inference of message manager types: Inference of guild in MessageManager Aug 21, 2022
@Jiralite Jiralite added this to the discord.js v14.3 milestone Aug 21, 2022
@codecov
Copy link

codecov bot commented Aug 21, 2022

Codecov Report

Merging #8538 (892f48d) into main (27bbc8f) will decrease coverage by 13.54%.
The diff coverage is n/a.

❗ Current head 892f48d differs from pull request most recent head 1ca12d8. Consider uploading reports for the commit 1ca12d8 to get more accurate results

@@             Coverage Diff              @@
##              main    #8538       +/-   ##
============================================
- Coverage   100.00%   86.45%   -13.55%     
============================================
  Files           39       87       +48     
  Lines         3018     8462     +5444     
  Branches       406     1105      +699     
============================================
+ Hits          3018     7316     +4298     
- Misses           0     1103     +1103     
- Partials         0       43       +43     
Flag Coverage Δ
builders 100.00% <ø> (ø)
collection 100.00% <ø> (?)
proxy 73.28% <ø> (?)
rest 92.53% <ø> (?)
utilities 100.00% <ø> (?)
voice 64.08% <ø> (?)
ws 59.57% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
packages/builders/src/components/Component.ts 100.00% <0.00%> (ø)
packages/builders/src/components/button/Button.ts 100.00% <0.00%> (ø)
packages/builders/src/interactions/modals/Modal.ts 100.00% <0.00%> (ø)
...s/src/interactions/slashCommands/options/number.ts 100.00% <0.00%> (ø)
.../src/interactions/slashCommands/options/integer.ts 100.00% <0.00%> (ø)
...trategies/context/SimpleContextFetchingStrategy.ts 71.42% <0.00%> (ø)
packages/voice/src/networking/Networking.ts 3.18% <0.00%> (ø)
...es/ws/src/strategies/sharding/IShardingStrategy.ts 100.00% <0.00%> (ø)
packages/voice/src/receive/VoiceReceiver.ts 90.56% <0.00%> (ø)
.../src/strategies/sharding/SimpleShardingStrategy.ts 73.43% <0.00%> (ø)
... and 43 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@vercel vercel bot temporarily deployed to Preview August 22, 2022 08:28 Inactive
@kodiakhq kodiakhq bot merged commit 6bb1474 into discordjs:main Aug 22, 2022
@Jiralite Jiralite deleted the types/message-manager-in-guild branch August 22, 2022 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants