Error handling for automatic TTS request
This commit is contained in:
		
							parent
							
								
									09e3c4307c
								
							
						
					
					
						commit
						0adc21d73e
					
				| @ -251,6 +251,7 @@ async function scheduleRandomMessage(firstTime = false) | |||||||
|         } |         } | ||||||
|         const randomMessage = await fetchMotd(); |         const randomMessage = await fetchMotd(); | ||||||
|         if (randomMessage) { |         if (randomMessage) { | ||||||
|  |             try { | ||||||
|                 const audio = await requestTTSResponse(randomMessage); |                 const audio = await requestTTSResponse(randomMessage); | ||||||
|                 const audioBuf = await audio.arrayBuffer(); |                 const audioBuf = await audio.arrayBuffer(); | ||||||
|                 const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav'); |                 const audioFile = new AttachmentBuilder(Buffer.from(audioBuf)).setName('mikuified.wav'); | ||||||
| @ -258,7 +259,12 @@ async function scheduleRandomMessage(firstTime = false) | |||||||
|                     content: randomMessage, |                     content: randomMessage, | ||||||
|                     files: [audioFile] |                     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 { |         } else { | ||||||
|             logWarn(`[bot] Could not fetch MOTD.`); |             logWarn(`[bot] Could not fetch MOTD.`); | ||||||
|         } |         } | ||||||
|  | |||||||
| @ -4,7 +4,7 @@ import { | |||||||
|     SlashCommandBuilder |     SlashCommandBuilder | ||||||
| } from 'discord.js'; | } from 'discord.js'; | ||||||
| import 'dotenv/config'; | import 'dotenv/config'; | ||||||
| import { logError, logInfo, logWarn } from '../../../logging'; | import { logError } from '../../../logging'; | ||||||
| import { requestTTSResponse } from '../../util'; | import { requestTTSResponse } from '../../util'; | ||||||
| 
 | 
 | ||||||
| const config = { | const config = { | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user