0
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?

Webhookを使ってdiscordに文字を投稿する

Posted at

はじめまして、どららといいます
今回が最初の記事ということでwebhookを使ってdiscordに文字を投稿する方法を解説します

まず最初にwebhook?って何という人に超簡単に解説します

webhookは「何かが起きたときに、自動で他のサービスに通知する仕組みのことです」

やり方

1.discordのサーバーでwebhookの設定をする
最初にサーバーの設定を開きます
そしたら、左下の連携サービス、からwebhookを選択します
Screenshot 2025-04-28 15.44.51.png
そして新しいウェブフックをおします
Screenshot 2025-04-28 15.49.45.png
webhookのurlをコピーしましょう
Screenshot 2025-04-28 15.51.45.png
discordの作業はこれでおしまい

例のコードです

const url = 'さっきのwebhookのurl';

const postData = {
  content: 'JSからのWebhookテスト' //メッセージ(その他オプションもあるよ)
}

const main = async () => {
  const response = await fetch(url, {
    method: 'POST',
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(postData)
  });

  console.log(response.status);
}

main();

このコードをnodejsで実行しましょう
そしたらdiscordでJSからのWebhookテストと表示されてるはず!
image.png
あとは自分で色々いじってみてください!

おしまい!!

0
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
0
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?