diff --git a/bot/static/index.html b/bot/static/index.html
index b72ba1f..1471042 100644
--- a/bot/static/index.html
+++ b/bot/static/index.html
@@ -2544,12 +2544,15 @@ async function updateBedtimeRange(guildId) {
const [startHour, startMinute] = startTime.split(':').map(Number);
const [endHour, endMinute] = endTime.split(':').map(Number);
+ const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
+ const originalText = button ? button.textContent : 'Update Bedtime Range';
+
try {
// Show loading state
- const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
- const originalText = button.textContent;
- button.textContent = 'Updating...';
- button.disabled = true;
+ if (button) {
+ button.textContent = 'Updating...';
+ button.disabled = true;
+ }
// Send the update request
const response = await fetch(`/servers/${guildIdStr}/bedtime-range`, {
@@ -2579,9 +2582,8 @@ async function updateBedtimeRange(guildId) {
} catch (error) {
console.error('Failed to update bedtime range:', error);
showNotification(error.message || 'Failed to update bedtime range', 'error');
-
+ } finally {
// Restore button state
- const button = document.querySelector(`button[onclick="updateBedtimeRange('${guildIdStr}')"]`);
if (button) {
button.textContent = originalText;
button.disabled = false;