Error handling for automatic TTS request

This commit is contained in:
James Shiffer 2024-05-11 05:15:45 +00:00
parent 09e3c4307c
commit 0adc21d73e
3 changed files with 23 additions and 17 deletions

View File

@ -251,6 +251,7 @@ async function scheduleRandomMessage(firstTime = false)
}
const randomMessage = await fetchMotd();
if (randomMessage) {
try {
const audio = await requestTTSResponse(randomMessage);
const audioBuf = await audio.arrayBuffer();
const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav');
@ -258,7 +259,12 @@ async function scheduleRandomMessage(firstTime = false)
content: randomMessage,
files: [audioFile]
});
logInfo(`[bot] Sent MOTD: ${randomMessage}`);
logInfo(`[bot] Sent MOTD + TTS: ${randomMessage}`);
} catch (err) {
await channel.send(randomMessage);
logWarn(`[bot] Could not fetch MOTD TTS: ${err}`);
logInfo(`[bot] Send text MOTD: ${randomMessage}`);
}
} else {
logWarn(`[bot] Could not fetch MOTD.`);
}

View File

@ -4,7 +4,7 @@ import {
SlashCommandBuilder
} from 'discord.js';
import 'dotenv/config';
import { logError, logInfo, logWarn } from '../../../logging';
import { logError } from '../../../logging';
import { requestTTSResponse } from '../../util';
const config = {