LoginSignup
1
0

DiscordのWebhookを使ってテスト投稿を実行(Python)

Posted at

DiscordのBOTを作る機会があったので備忘録代わりに残していきます。
他に良い方法があるのかもしれませんが、
ひとまずPythonとcronを使ってBOTを作ろうとしています。

Discordのウェブフックを使ってテスト投稿する

コマンドプロンプトから直接実行

import requests

webhook_url = "webフックURL"

def send_dummy_message():
    message = "これはダミーのテスト投稿です。"
    data = {
        "content": message
    }
    headers = {
        "Content-Type": "application/json"
    }
    response = requests.post(webhook_url, json=data, headers=headers)
    if response.status_code == 204:
        print("ダミーの投稿に成功しました。")
    else:
        print(f"ダミーの投稿に失敗しました。ステータスコード: {response.status_code}, レスポンス: {response.text}")

if __name__ == "__main__":
    send_dummy_message()

投稿を実行するところまで出来たの備忘録として( ..)φ

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