THREAD_CREATE event Listener run method arguments
What I want to do:
I want to inspect the id of the parent channel where the thread was created.
The code I tried:
The result I got:
stringify
on the thread can determine the parent_id
, but when accessed as an argument to the run
method, it returns undefined.
What am I missing?
Thanks,Solution:Jump to solution
Any event emitted by the discordjs websocket, such as THREAD_CREATE, doesn't receive a discordjs class, such as ThreadChannel, as first parameter. It receives the raw discord API data. If you type it as the type from discord-api-types (dunno which) you'll get the right properties in your code.
My guess is that it's an APIThreadChannel https://discord-api-types.dev/api/discord-api-types-v10/interface/APIThreadChannel
The
ws
event also receives only ONE argument which is that APIThreadChannel
, there is no second argument NewlyCreated
. That gets inserted by DiscordJS....discord-api-types documentation
discord-api-types - Imagine typings
discord-api-types is a simple Node/Deno module that brings up to date typings for Discord's API
2 Replies
Solution
Any event emitted by the discordjs websocket, such as THREAD_CREATE, doesn't receive a discordjs class, such as ThreadChannel, as first parameter. It receives the raw discord API data. If you type it as the type from discord-api-types (dunno which) you'll get the right properties in your code.
My guess is that it's an APIThreadChannel https://discord-api-types.dev/api/discord-api-types-v10/interface/APIThreadChannel
The
ws
event also receives only ONE argument which is that APIThreadChannel
, there is no second argument NewlyCreated
. That gets inserted by DiscordJS.
That said, you're far better off just rewriting it to the DiscordJS client event emitter:
discord-api-types documentation
discord-api-types - Imagine typings
discord-api-types is a simple Node/Deno module that brings up to date typings for Discord's API
It was a huge help!
I verified the normal behavior with the code you wrote.
Thank you!