2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

「今日はどこ出社?」をなくすために出社場所確認を自動化した(GAS + Discord)

2
Last updated at Posted at 2026-03-13

自己紹介

株式会社アマテックでエンジニアとしてアルバイトをしている颯太です
普段は Web 開発や自動化ツールの開発などをしています

今回は、社内で運用している 出社場所確認フローを自動化した話を書きます

導入した経緯

弊社では Google Calendar でシフトを決めています

ただし、出社場所は固定ではありません

人数によって

  • オフィス
  • カフェ

のどちらかになります

そしてカフェの場合、場所は社長が決めるため

「明日はどこ出社?」

という会話が頻繁に発生していました

さらにカフェの場所は 社長の気分で決まることも多く
前日まで決まっていないこともありました

その結果

  • 朝に出社場所を確認する
  • 支度中に連絡を待つ

といった状況が発生していました

そこで

前日の夕方に「明日出社する人」を自動で通知する仕組み

を作ることにしました

仕組み

システムの構成はシンプルです

  1. Google Calendar から「明日の予定」を取得
  2. 出社予定の人を取得
  3. Discord にメンション付きで通知

実装

GAS で次のようなスクリプトを書きました

function main() {
  const calendarId = '';
  const webhookUrl = 'https://discord.com/api/webhooks/';

  const triggers = ScriptApp.getProjectTriggers();
  for (const t of triggers) {
    if (t.getHandlerFunction() === 'main') {
      ScriptApp.deleteTrigger(t);
    }
  }

  const next = new Date();
  next.setDate(next.getDate() + 1);
  next.setHours(17, 0, 0, 0);
  ScriptApp.newTrigger('main').timeBased().at(next).create();

  const tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  const start = new Date(tomorrow.setHours(0, 0, 0, 0));
  const end = new Date(tomorrow.setHours(23, 59, 59, 999));

  const events = CalendarApp.getCalendarById(calendarId).getEvents(start, end);
  if (events.length === 0) return;

  const authorMap = {};
  for (const event of events) {
    const creator = event.getCreators()[0] || event.getGuestList()[0]?.getEmail() || null;
    if (creator) authorMap[creator] = true;
  }
  if (Object.keys(authorMap).length === 0) return;

  const discordIdMap = {
    'example1@gmail.com': 'discordUserID1',
    'example2@gmail.com': 'discordUserID2'
  };

  const userIds = Object.keys(authorMap)
    .map(email => discordIdMap[email])
    .filter(id => id)
    .map(id => `<@${id}>`);

  if (userIds.length === 0) return;

  const userText = userIds.length === 1
    ? `${userIds[0]} が出社します`
    : `${userIds.join('')} が出社します`;

  const message = {
    content: `明日は ${userText}`
  };

  UrlFetchApp.fetch(webhookUrl, {
    method: 'post',
    contentType: 'application/json',
    payload: JSON.stringify(message)
  });
}

ポイント

明日の予定を取得

CalendarApp.getCalendarById(calendarId).getEvents(start, end)

で明日のイベントを取得しています

メールアドレスから Discord ID を取得

Google Calendar ではユーザーを メールアドレスで取得できるため
Discord ID との対応表を作っています

const discordIdMap = {
  'example@gmail.com': '1234567890'
};

Discord Webhook で通知

UrlFetchApp.fetch(webhookUrl, {
  method: 'post',
  contentType: 'application/json',
  payload: JSON.stringify(message)
});

これだけで Discord に通知できます

効果

この仕組みを導入したことで

  • 前日に出社場所が決まる
  • 朝に連絡を待つ必要がなくなる

という状態になりました!

また個人的にも

  • 明日出社することが前日にわかる
  • 早めに寝る判断ができる

というメリットがありました

まとめ

GAS と Discord Webhook を使うと
ちょっとした社内フローを簡単に自動化できます

今回の例のように

  • Google Calendar
  • GAS
  • Discord

を組み合わせるだけで、かなり便利な仕組みが作れます

もし同じように

「明日誰が出社するの?」

といった確認が発生している場合は、ぜひ自動化してみてください

読んでいただきありがとうございました

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?