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

MessageManager#fetch has signatures, but none of those signatures are compatible with each other. #8545

Closed
ImRodry opened this issue Aug 22, 2022 · 11 comments · Fixed by #9612

Comments

@ImRodry
Copy link
Contributor

ImRodry commented Aug 22, 2022

Which package is this bug report for?

discord.js

Issue description

On v14.3.0, when you fetch the messages of a channel through message.channel.messages.fetch() without narrowing down the type of message.channel you get a Collection of Message or Message. Upon trying to call .filter on this collection, you will get the following error:
This expression is not callable.
Each member of the union type '{ (fn: (value: Message, key: string, collection: Collection<string, Message>) => key is K2): Collection<K2, Message>; <V2 extends Message<...>>(fn: (value: Message<...>, key: string, collection: Collection<...>) => value is V2): Collection<...>; (fn: (value: Message<...>, key: st...' has signatures, but none of those signatures are compatible with each other. ts(2349)

This is because, since the message manager can come from multiple types of channels, the boolean type parameter can be true or false, and those two are not compatible with each other, thus TS cannot infer the type of the resulting filtered Collection

Code sample

client.on("message", async message => {
    (await message.channel.messages.fetch()).filter(m => m.author.id === message.author.id)
})

Package version

14.3.0

Node.js version

18.7.0

Operating system

Windows 11

Priority this issue should have

High (immediate attention needed)

Which partials do you have configured?

Not applicable (subpackage bug)

Which gateway intents are you subscribing to?

Not applicable (subpackage bug)

I have tested this issue on a development release

No response

@ImRodry
Copy link
Contributor Author

ImRodry commented Sep 21, 2022

I haven’t been able to update since v14.3.0 due to this issue. Can this be fixed asap please?

@RedGuy12
Copy link
Contributor

I was looking in to this. I initially thought to change TextBasedChannel's definitions, but it's just an exclusion of Channel, so modifying that wouldn't fix it. There's no BaseTextChannel class I can modify. Each channel extends BaseChannel which isn't always a TextChannel so I can't change that.

Could anyone help point me in the right direction with this? Thanks!

@ararouu
Copy link

ararouu commented Jan 18, 2023

I am also having the same issue with this. I am currently trying to make a purge command that clears messages from a user, and whenever I try to filter the messages to push them to an array and it filter out the author ID, it gives this error. Even on discord.js v14.7.1. Update: from what it seems, it's probably effecting versions newer than 14.3.0. Downgrading to 14.2.0 fixed it for me, so idk what the hell they did.

@jaw0r3k
Copy link
Contributor

jaw0r3k commented Jan 21, 2023

So looks like its effected by #8538

@ararouu
Copy link

ararouu commented Jan 21, 2023

prob

@ararouu
Copy link

ararouu commented Feb 10, 2023

So, I have found the issue. In order to use messages.filter, the channel you are fetching messages from needs to be as TextChannel. Doing const messages = await (<Channel> as TextChannel).messages.fetch(); and then messages.filter() should work.

@Jiralite
Copy link
Member

That is not relevant to this issue. If you only care about text channels, you should check the channel's type.

@ararouu
Copy link

ararouu commented Feb 10, 2023

That is not relevant to this issue. If you only care about text channels, you should check the channel's type.

Either way works, if you check the channels type is GuildText or casting it.

@ImRodry
Copy link
Contributor Author

ImRodry commented Feb 10, 2023

Except that is not a valid solution because this issue happens when you want to check the messages from any text based channel

@nukeop
Copy link

nukeop commented Mar 21, 2023

I'm running into the same problem. Gotta @ts-ignore around this thing.

@ImRodry
Copy link
Contributor Author

ImRodry commented Aug 10, 2023

This issue has now also been resolved on TS as of v5.2 so for people in previous versions the fix will be to update TS. There is a caveat though that is explained in https://devblogs.microsoft.com/typescript/announcing-typescript-5-2-rc/#easier-method-usage-for-unions-of-arrays

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants