RYU
RYU
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:
import { Listener } from '@sapphire/framework'
import type { ThreadChannel } from 'discord.js'

export class ForumListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: 'ws',
event: 'THREAD_CREATE',
})
}

public run(thread: ThreadChannel, newlyCreated: boolean) {
const string = JSON.stringify(thread, null, 2)
console.log(thread.parentId, newlyCreated)
console.log(string)
}
}
import { Listener } from '@sapphire/framework'
import type { ThreadChannel } from 'discord.js'

export class ForumListener extends Listener {
public constructor(context: Listener.Context, options: Listener.Options) {
super(context, {
...options,
emitter: 'ws',
event: 'THREAD_CREATE',
})
}

public run(thread: ThreadChannel, newlyCreated: boolean) {
const string = JSON.stringify(thread, null, 2)
console.log(thread.parentId, newlyCreated)
console.log(string)
}
}
The result I got:
console.log(thread.parentId, newlyCreated) // undefined 0
console.log(thread.parentId, newlyCreated) // undefined 0
{
"type": 11,
"total_message_sent": 0,
"thread_metadata": {
"locked": false,
"create_timestamp": "2023-03-05T11:39:42.536000+00:00",
"auto_archive_duration": 4320,
"archived": false,
"archive_timestamp": "2023-03-05T11:39:42.536000+00:00"
},
"rate_limit_per_user": 0,
"parent_id": "1081883195349405746",
"owner_id": "xxx",
"newly_created": true,
"name": "test",
"message_count": 0,
"member_count": 1,
"last_message_id": null,
"id": "1081903866334937118",
"guild_id": "xxx",
"flags": 0
}
{
"type": 11,
"total_message_sent": 0,
"thread_metadata": {
"locked": false,
"create_timestamp": "2023-03-05T11:39:42.536000+00:00",
"auto_archive_duration": 4320,
"archived": false,
"archive_timestamp": "2023-03-05T11:39:42.536000+00:00"
},
"rate_limit_per_user": 0,
"parent_id": "1081883195349405746",
"owner_id": "xxx",
"newly_created": true,
"name": "test",
"message_count": 0,
"member_count": 1,
"last_message_id": null,
"id": "1081903866334937118",
"guild_id": "xxx",
"flags": 0
}
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,
5 replies