#ERROR: Cannot message this thread until after the post author has sent an initial message

1 messages · Page 1 of 1 (latest)

hallow needle

I'm trying to send a message right after a thread creation. But sometimes i receive this error:

Error sending message in thread: DiscordAPIError[40058]: Cannot message this thread until after the post author has sent an initial message.

I believe that discord has some small delay to publish the author message, due that i guess i have to wait for something but i dont know what do i have to listen for.

Code:

    client.on('threadCreate', async (thread) => {
        try {
            if (thread.parentId !== process.env.CHANNEL_ID) return;
            if (!thread.joinable) return;
            await thread.join();

            await thread.send({
                content: `<@${thread.ownerId}>, message content`,
            });

        } catch (error) {
            console.error(`Error sending message in thread: ${error}`);
        }
    });