Raid Reminder: Discord DM Automation For Signups
Hey guys! Let's dive into how we can automate sending Discord DM reminders to our raid signups. This is all about making sure everyone's prepped and ready to go, without you having to chase people down manually. We're talking about using Google Apps Script magic to send those reminders exactly 4 hours before the raid kicks off.
Description
Imagine a world where guild members automatically get a Discord DM reminder, personalized and timely, just before a raid. That's the goal! This system uses time-based triggers in Google Apps Script to actively scan for upcoming raids. When it spots one that's 4 hours away, it springs into action, sending out DMs via Discord webhooks. No more missed raids or last-minute scrambles!
Acceptance Criteria
To make sure this system rocks, here's what we need to nail:
- Time-Based Trigger: The script needs to check for raids starting in approximately 4 hours. This is the core of our automation.
- Opt-In Only: DMs should only go to those who've specifically asked for them, usually via a checkbox in the signup sheet. Respecting preferences is key.
- Detailed DMs: Each DM needs to have the crucial raid info – time, raid type, and the user's role/spec, if applicable. The more info, the better!
- Frequency Matters: The trigger must run often enough to catch raids within that 4-hour window. Think every 30 minutes or so.
- DM Delivery: We'll use Discord user webhooks or a bot's DM capability to send these reminders. Delivery is everything.
- No Spam: Users should only get one reminder per raid. Nobody likes getting spammed.
- Handle Dropouts: The system should gracefully handle users who've left Discord or blocked DMs. No error messages or broken code.
Deep Dive Into Implementation
Alright, let's get into the nitty-gritty. This is where we talk about how to actually make this happen. The main goal is to automate the process of sending Discord direct messages (DMs) to guild members who have signed up for raid reminder notifications, specifically 4 hours before the scheduled raid time. This automation leverages the power of Google Apps Script and Discord webhooks to create a seamless reminder system.
Core Components and Technologies
- Google Apps Script: This is the backbone of our automation. Google Apps Script allows us to write code that interacts with Google Sheets (where raid sign-ups are likely stored) and external services like Discord.
- Time-Based Triggers: We'll use time-based triggers within Google Apps Script to schedule the execution of our reminder-sending function. This ensures that the script runs automatically at regular intervals, checking for upcoming raids.
- Discord Webhooks: Discord webhooks provide a way for external services (like our Google Apps Script) to post messages to Discord channels or send DMs to users. We'll leverage webhooks to send personalized raid reminders to guild members.
- Raid Sign-Up Sheet (Google Sheets): This is where guild members sign up for raids and indicate whether they want to receive reminders. The sheet will contain information about raid times, raid types, user roles, and reminder preferences.
Step-by-Step Implementation
- Set Up the Raid Sign-Up Sheet:
- Create a Google Sheet to serve as the raid sign-up sheet.
- Include columns for:
- Member's Discord ID (or a unique identifier that can be mapped to a Discord user).
- Raid Time (date and time of the raid).
- Raid Type (e.g., Vault of Glass, King's Fall).
- Member's Role (e.g., DPS, Healer, Tank).
- Reminder Preference (a checkbox indicating whether the member wants to receive reminders).
- Create a Google Apps Script:
- Open the Google Sheet and go to "Tools" > "Script editor" to create a new Google Apps Script project.
- Write a function called
checkUpcomingRaids()that will be responsible for checking for upcoming raids and sending reminders.
- Implement the
checkUpcomingRaids()Function:- Fetch Raid Data: Use the
SpreadsheetAppservice to access the raid sign-up sheet and retrieve the raid data. - Iterate Through Raids: Loop through each row in the sheet to process the raid sign-ups.
- Check Reminder Preference: For each sign-up, check the "Reminder Preference" checkbox to see if the member wants to receive reminders.
- Calculate Time Difference: Calculate the time difference between the raid time and the current time using
(raidTime - new Date()) / (1000 * 60 * 60)to determine if the raid is approximately 4 hours away. - Send Discord DM Reminders: If the raid is 4 hours away and the member wants a reminder, send a personalized DM to the member via Discord webhook.
- Fetch Raid Data: Use the
- Set Up Discord Webhooks:
- There are two main approaches for sending DMs via webhook:
- Discord Bot Token (Requires Hosting): This approach involves creating a Discord bot and hosting it on a server. The bot can then use its token to send DMs directly to users.
- User-Specific Webhook URLs (Users Create These): This approach requires each user to create their own webhook URL and provide it to the script. The script can then use these webhook URLs to send DMs to the respective users.
- Choose the approach that best suits your needs and implement the necessary code to send DMs via webhook.
- There are two main approaches for sending DMs via webhook:
- Create Time-Based Trigger:
- Use the
ScriptApp.newTrigger('checkUpcomingRaids').timeBased().everyHours(1).create()function to create an installable time-driven trigger that runs thecheckUpcomingRaids()function every hour.
- Use the
Code Snippets and Examples
Here are some code snippets to help you get started:
- Fetching Raid Data from Google Sheets:
function checkUpcomingRaids() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName("RaidSignups");
var dataRange = sheet.getDataRange();
var data = dataRange.getValues();
// Iterate through rows (skip header row)
for (var i = 1; i < data.length; i++) {
var row = data[i];
var discordId = row[0]; // Assuming Discord ID is in the first column
var raidTime = row[1]; // Assuming Raid Time is in the second column
var raidType = row[2]; // Assuming Raid Type is in the third column
var reminderPreference = row[3]; // Assuming Reminder Preference is in the fourth column
// Rest of the logic here
}
}
- Calculating Time Difference:
var timeDiff = (raidTime - new Date()) / (1000 * 60 * 60); // Hours
if (timeDiff > 3.9 && timeDiff < 4.1) { // Check if raid is approximately 4 hours away
// Send reminder
}
- Sending Discord DM via Webhook:
function sendDiscordDM(discordId, message) {
var webhookUrl = "YOUR_WEBHOOK_URL"; // Replace with your webhook URL
var payload = {
"content": message
};
var options = {
"method": "post",
"contentType": "application/json",
"payload": JSON.stringify(payload)
};
UrlFetchApp.fetch(webhookUrl, options);
}
Best Practices and Considerations
- Error Handling: Implement robust error handling to catch and log any errors that may occur during the process. This will help you identify and fix issues quickly.
- Rate Limiting: Be mindful of Discord's rate limits to avoid getting your webhook blocked. Implement delays or batching to stay within the limits.
- Security: If you're using user-specific webhook URLs, ensure that they are stored securely and that users are aware of the risks involved.
- Testing: Thoroughly test your implementation with different scenarios to ensure that it works as expected.
Technical Notes
Here are some of the more granular details that might need some attention:
- Time-Driven Trigger: Use this to automatically run the script:
ScriptApp.newTrigger('checkUpcomingRaids').timeBased().everyHours(1).create(). - DM Delivery Options:
- Discord Bot Token: Requires hosting, sends DMs directly.
- User-Specific Webhook URLs: Users create these themselves.
- Alternative: Post a reminder in a channel with @mentions. A bit less personal, but simpler.
- Time Math:
(raidTime - new Date()) / (1000 * 60 * 60)gives you the time difference in hours. - Duplicate Prevention: Track sent reminders in the sheet. Add a "Reminder Sent" column.
- Time Zones: Consider time zone handling if raid times are in a specific zone.
Testing Requirements
Testing is crucial. Here’s what we need to verify:
- 3.5-Hour Test: Raid scheduled 3.5 hours from now should trigger a reminder.
- 5-Hour Test: Raid scheduled 5 hours from now should not trigger a reminder.
- Opt-In Test: User who opted in should get a DM.
- Opt-Out Test: User who didn't opt in should not get a DM.
- Duplicate Test: Only one reminder per user per raid. No repeats!
- Invalid User Test: Graceful handling of invalid Discord IDs. No crashes!
Files to Modify (if known)
- Google Apps Script file: This will house the new
checkUpcomingRaids()function. - Raid signup sheet: You might need to add a "Reminder Sent" column to the raid signup sheet
- Script triggers configuration
By implementing these features and meeting the acceptance criteria, you'll have a robust system that ensures everyone is reminded about upcoming raids, improving attendance and overall guild coordination. Let's get this done, guys!