James Stewart
James Stewart

Reputation: 21

Google App Script to mention discord user via webhook

I am looking to mention a user in a discord channel based on information set in a google sheet.

I have the script already pushing content from the google sheet to the discord channel so know that is working.

I can also get it to use the @everyone tag to mention everyone.

I am now wanting to get it set so that it only will mention the user.

Below is my script so far:

function onEdit() {
    var wsID = "  "
    var sheet = SpreadsheetApp.openById(wsID).getSheetByName('discord');

    var firestaff = sheet.getRange("A1").getValue();
    var firecourse = sheet.getRange("B1").getValue();
    var policestaff = sheet.getRange("A4").getValue();
    var policecourse = sheet.getRange("B4").getValue();
    var rescuestaff = sheet.getRange("A14").getValue();
    var rescuecourse = sheet.getRange("B14").getValue();

    var discordUrl = "",
    options;

    var firepayload = JSON.stringify({
        content: "Please can " + firestaff + " start the " + firecourse + " courses. "
    });

    var policepayload = JSON.stringify({
        content: "Please can " + policestaff + " start the " + policecourse + " courses.",
    });

    var rescuepayload = JSON.stringify({
        content: "Please can " + rescuestaff + " start the " + rescuecourse + " courses."
    });

    var policemention = JSON.stringify({
        content: "@everyone ",

    })

    var ssurl = JSON.stringify({
        content: "  "
    });

    var fireparams = {
        method: "POST",
        payload: firepayload,
        muteHttpExceptions: true,
        contentType: "application/json"
    };

    var policeparams = {
        method: "POST",
        payload: policepayload,
        muteHttpExceptions: true,

        contentType: "application/json"
    };
    var rescueparams = {
        method: "POST",
        payload: rescuepayload,
        muteHttpExceptions: true,
        contentType: "application/json"
    };

    var urlperms = {
        method: "POST",
        payload: ssurl,
        muteHttpExceptions: true,
        contentType: "application/json"
    };

    var policemen = {
        method: "POST",
        payload: policemention,
        muteHttpExceptions: true,
        contentType: "application/json"
    };

    UrlFetchApp.fetch(discordUrl, policemen)

    UrlFetchApp.fetch(discordUrl, fireparams);

    UrlFetchApp.fetch(discordUrl, policeparams);

    UrlFetchApp.fetch(discordUrl, rescueparams);

    UrlFetchApp.fetch(discordUrl, urlperms);
}

Upvotes: 2

Views: 994

Answers (1)

NEWAZA
NEWAZA

Reputation: 1630

The only method available will be to create and store a list of users and their IDs, tagging them with <@THEUSERID>.

You can get the user IDs by right-clicking on a user's avatar.

Upvotes: 1

Related Questions