discord / discord-api-docs

Official Discord API Documentation
https://discord.com/developers/docs/intro
Other
5.96k stars 1.26k forks source link

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

Open MinnDevelopment opened 1 year ago

MinnDevelopment commented 1 year ago

Description

When you try making a bot that posts instruction messages on every new forum post, the API returns the following error:

{
  "code": 40058
  "message": "Cannot message this thread until after the post author has sent an initial message"
}

Handling this from the bot perspective seems janky. Would it be possible for discord to handle this more gracefully, potentially by giving it a few seconds before returning an error?

The Documentation also uses this error code in a completely unrelated way:

40058: Cannot send a message in a forum channel

To me, this refers to the forum channel itself, rather than posts within it. At the very least, I would ask for a different error code to be used.

Additionally: Why does this error exist? What is the motivation behind it?

Steps to Reproduce

Send a message on every new thread, it will break if you're fast enough.

Expected Behavior

This error shouldn't happen.

Current Behavior

This error happens.

Screenshots/Videos

No response

Client and System Information

API v10

MicheleDiMezzaCutillo commented 1 year ago

I have this error, when a Thread channel is created in a forum, my bot posts a message in that channel. Once every 5-6 new threads, this error is launched, for now I'm trying to solve it by setting a second of delay so that the instant the thread is created, the bot waits for it to actually be created, so that then when it tries to send the message, don't give the error, because when creating a channel the bot could try to send the message too early and therefore give the error.

Soheab commented 1 year ago

I would like to add to this that it only happens to me when there are any attachments on the starter message.

Edit: adding a delay works

almostSouji commented 1 year ago

I respond with a thread welcomer (what you need to provide, button to mark solved, etc.) on new threads in our support forums. I currently work around this with a 2s timeout, but that's obviously less than ideal. It does not only, but more regularly, happen when people attach screenshots (without the workaround in place).

Herbherth commented 1 year ago

I've solved this without relying in preset delays posting my solution here to help whoever is having this problem:

async function WaitStarterMessage(thread){
    try {
        const message = await thread.fetchStarterMessage();
        return message;
    } catch (error) {
        if(error.name != "DiscordAPIError[10008]")
        {
            console.log(error);
            process.exit();
        }
        return null;
    }
}

than, in my code, before everything, I just put it:

let firstMessage;
    do{
        firstMessage = await WaitStarterMessage(thread);
    }while(!firstMessage)

in my function WaitStarterMessage I checked the error to avoid infinite loops in case the error is different from 'Unknown message'. Worked fine here ;D

Also, if you wish, you can use the firstMessage variable after (I use it to retrieve some infos that my bot uses)