4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【覚書】GoogleフォームからDiscordに匿名投稿する【GAS】

Last updated at Posted at 2021-04-26

Google フォームにて送信した内容を、
Discord に Webhook 経由で投稿する方法。

匿名チャットを作りたい人用。

Discord 側の設定

  1. サーバー設定 -> 連携サービス
  2. ウェブフックを作成
  3. 「ウェブフック URL」を控えておく

Google 側の設定

  1. Google ドライブから Google フォームを作成
  2. 「発言」という質問名で「記述式」の入力欄だけ作成
  3. 「スクリプトエディタ」を開く
  4. 以下のコードをコピペ
const WEBHOOK_URL = "ウェブフックURL";

FormApp.getActiveForm();

const onSubmit = (e) => {
  const data = e.response
    .getItemResponses()
    .reduce(
      (p, c) => ({ ...p, [c.getItem().getTitle()]: c.getResponse() }),
      {}
    );
  const request = {
    method: "post",
    "content-type": "application/json",
    payload: {
      content: data["発言"],
    },
  };
  UrlFetchApp.fetch(WEBHOOK_URL, request);
};
  1. "ウェブフックURL" を控えておいた URL に書き換える
  2. 新しいデプロイ -> 種類の選択 -> ウェブアプリ
  3. 次のユーザーとして実行を「自分」、アクセスできるユーザーを「全員」に設定(目的に応じて変える)
  4. onSubmit を実行すると fetch 権限を聞かれるので認証して許可する
  5. Google フォームから発言を入力して、問題なく投稿されれば完成。
4
3
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
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?