Send and delivery order #1071
-
Part of the guide or code sample the question is aboutNot found. New question. QuestionHow to guarantee the send and delivery order, as a bot developer? Say my bot sends message A, B, C, D, ... one by one, but B is a image/photo message. I found that the delivery order becomes A, C, D, ... , B. As per #1054, the messages are queued in internal queues, but why the delivery is out of the order? Is there anyway to guarantee the delivery order please? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments
-
You can await the promises of messages to make sure they are sent in order: await message.channel.send("Hi mom!")
await message.channel.send("Big image")
await message.channel.send("Hello world!") |
Beta Was this translation helpful? Give feedback.
-
Well, change your second message from "Big image" text message to a true image message, and you'll see for yourself what I'm talking about. Hmm..., hold on, maybe you're right. The situation is that my discordjs bot relays message to another channel in a event-driven fashion. When my bot receives message A, B, C, D, ... one by one, it will sends them one by one with Although the messages sent in the following way keeps their order,
Due to such event-driven nature, as the result, the delivery order in the receiving channel will be out of the order -- Seems that the messages are not queued internally in a single queue, but each event-driven handler uses its own queue. |
Beta Was this translation helpful? Give feedback.
-
Discord.js sends REST commands off to the API, which handles them and propagates the sent message to clients via the websocket. As soon as the REST request resolves, discord.js will update the cache and send the next message. The REST API response may resolve before the messages can be propagated and arrive at your client. This may or may not be solved by reloading the client, in which case messages are fetched and sorted by their creation time (included in the message-id - snowflake). If it is not solved after a refresh that'd imply that the sequence of message creation is broken at the API level. Theoretically this could still result in the observed behavior, if the text messages is quicker to distribute via ws, while the image is being uploaded to the CDN and only propagated afterwards (I'm not exactly aware of these inner workings, so this is mostly guesswork). |
Beta Was this translation helpful? Give feedback.
Discord.js sends REST commands off to the API, which handles them and propagates the sent message to clients via the websocket. As soon as the REST request resolves, discord.js will update the cache and send the next message. The REST API response may resolve before the messages can be propagated and arrive at your client.
This may or may not be solved by reloading the client, in which case messages are fetched and sorted by their creation time (included in the message-id - snowflake). If it is not solved after a refresh that'd imply that the sequence of message creation is broken at the API level. Theoretically this could still result in the observed behavior, if the text messages is qui…