Open faruk-avci opened 2 months ago
I encountered this too, but I think part of the issue is that when you get a 200 return code from sending a message, that isn't saying that the message has arrived, it's saying the request to send it has.
When I caught errors explicitly, I could see the underlying error message, usually a kick error like Too many special characters etc (helps to mod the bot). May have to change a few things but the below code had my bot sending the error it retrieved to chat, but you could optionally just log it to console.
async sendMessage(channel, message) {
try {
const targetChannel = this.channels.find(ch => ch.data.chatroom.id === channel);
if (targetChannel) {
const response = await this.chat.api.chat.sendMessage(targetChannel.data.chatroom.id, message);
if (response.status && response.status.error) {
const { status, code, message: errorMessage } = response.status;
global.tools.logWithPlatform('kick', `Extracted error details - Status: ${status}, Code: ${code}, Message: ${errorMessage}`);
throw new KickApiError('Error sending message', status, code, errorMessage);
}
}
} catch (error) {
//console.dir(error, { depth: null }); <- contents of error object
global.tools.logWithPlatform('kick', `Error sending message: ${error.message}`);
const errorMessage = error.cause && error.cause.body && error.cause.body.status
? `Error: ${error.cause.body.status.message} (Code: ${error.cause.body.status.code}, Status: ${error.cause.body.status.status})`
: `Error: ${error.message}`;
await this.sendMessageToChannel(channel, errorMessage);
}
}
I have 10 bots sending messages to same chatroom and decided to put one second delay and didnt get any error so far. I dont know what changed but it seems fine for me. I will keep monitoring it to make sure it continues properly.
I logged into my account and sent some messages to a chat. Although the response body returns a status code of 200, sometimes I can't see the message in the chat. However, after waiting a bit and sending the message again, it does appear.
I'm not sure why this inconsistency is happening. Has anyone else experienced a similar issue, or could there be a delay in the message processing?