{"id":16207906,"url":"https://github.com/qwe321qwe321qwe321/unity-discordwebhook","last_synced_at":"2025-03-19T08:30:39.528Z","repository":{"id":246191374,"uuid":"820241811","full_name":"qwe321qwe321qwe321/Unity-DiscordWebhook","owner":"qwe321qwe321qwe321","description":"Send messages and files to Discord channels using webhooks. It provides a simple API for sending text messages, capturing and attaching screenshots, and even compressing and attaching log files for bug reports.","archived":false,"fork":false,"pushed_at":"2024-12-11T19:53:15.000Z","size":107,"stargazers_count":27,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-28T16:55:42.962Z","etag":null,"topics":["discord","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/qwe321qwe321qwe321.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-06-26T05:00:21.000Z","updated_at":"2024-12-27T03:19:08.000Z","dependencies_parsed_at":"2024-06-26T11:54:53.553Z","dependency_job_id":"14a9e435-38d9-41c8-bf1e-78afcdb8efaf","html_url":"https://github.com/qwe321qwe321qwe321/Unity-DiscordWebhook","commit_stats":null,"previous_names":["qwe321qwe321qwe321/unity-discordwebhook"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwe321qwe321qwe321%2FUnity-DiscordWebhook","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwe321qwe321qwe321%2FUnity-DiscordWebhook/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwe321qwe321qwe321%2FUnity-DiscordWebhook/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/qwe321qwe321qwe321%2FUnity-DiscordWebhook/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/qwe321qwe321qwe321","download_url":"https://codeload.github.com/qwe321qwe321qwe321/Unity-DiscordWebhook/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243976460,"owners_count":20377691,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["discord","unity"],"created_at":"2024-10-10T10:14:46.110Z","updated_at":"2025-03-19T08:30:39.522Z","avatar_url":"https://github.com/qwe321qwe321qwe321.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity-DiscordWebhook\n\n\nUnity-DiscordWebhook is a library that allows you to easily send messages and files to Discord channels using [webhooks](https://discord.com/developers/docs/resources/webhook). It provides a simple API for sending text messages, capturing and attaching screenshots, and even compressing and attaching log files for bug reports.\n\n## Features\n* [Sending messages and create posts/threads to text channels and forums.](#getting-started)\n* [Builder pattern for creating a message.](#getting-started)\n* Awaitable API with [UniTask](https://github.com/Cysharp/UniTask)\n* Unity Coroutine and EditorCoroutine API. (IEnumerator and callback)\n* A few Discord Bot API to query the server and channel information. \n  * See [DiscordBotApi.cs](/src/DiscordWebhook/Assets/DiscordWebhook/Utility/DiscordBotApi.cs).\n* Helper methods for creating a bug report.\n  * [Attach files by file path or byte array.](#create-a-post-in-a-forum-with-screenshots-and-log-files)\n  * [Attach images by Texture2D.](/src/DiscordWebhook/Assets/DiscordWebhook/WebhookBuilder.cs#L120)\n  * [Capture and attach screenshots by setting a flag.](#create-a-post-in-a-forum-with-screenshots-and-log-files)\n  * [Compress all attached files to a zip file by setting a flag.](#create-a-post-in-a-forum-with-screenshots-and-log-files)\n  * [Get the message URL after sending a message.](#create-a-post-in-a-forum-with-screenshots-and-log-files)\n \n## Table of Contents\n- [Setup](#setup)\n  - [Requirement](#requirement)\n  - [Installation](#installation)\n- [Getting Started](#getting-started)\n  - [Send a message to a text channel](#send-a-message-to-a-text-channel)\n  - [Create a post in a forum with screenshots and log files](#create-a-post-in-a-forum-with-screenshots-and-log-files)\n  - [How do I get tag IDs from the forum?](#how-do-i-get-tag-ids-from-the-forum)\n- [Use Cases](#use-cases)\n \n## Setup\n### Requirement \n* (Optional) [Cysharp/UniTask](https://github.com/Cysharp/UniTask)\n\t* We recommend using UniTask for asynchronous programming. However, you can use the library without it, we provide Unity Coroutine API as well.\n\t* If your UniTask is not installed from [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html), add the scripting define symbol `DISCORD_WEBHOOK_UNITASK_SUPPORT` to Project Settings.\n\n### Installation\nInstall via [Unity Package Manager](https://docs.unity3d.com/Manual/upm-ui.html).\n\n```\nhttps://github.com/qwe321qwe321qwe321/Unity-DiscordWebhook.git?path=src/DiscordWebhook/Assets/DiscordWebhook\n```\n\n## Getting Started\n\n### Send a message to a text channel\n[UniTaskSample.cs](/src/DiscordWebhook/Assets/Samples/UniTaskSample.cs)\n```csharp\nWebhookResponseResult result = await WebhookBuilder.CreateTextChannel(textChannelWebhookUrl)\n\t.SetUsername(\"MyBot\") // username is optional.\n\t.SetContent(\"Hello WORLD\") // content is required.\n\t.ExecuteAsync();\n// handle the result.\n```\n\n[CoroutineSample.cs](/src/DiscordWebhook/Assets/Samples/CoroutineSample.cs)\n```csharp\nWebhookBuilder.CreateTextChannel(textChannelWebhookUrl)\n\t.SetUsername(\"MyBot\") // username is optional.\n\t.SetContent(\"Hello WORLD\") // content is required.\n\t.ExecuteCoroutine(this, (result) =\u003e {\n    \t// handle the result with callback.\n\t}));\n```\n\n[EditorCoroutineSample.cs](/src/DiscordWebhook/Assets/Samples/Editor/EditorCoroutineSample.cs)\n```csharp\nWebhookBuilder.CreateTextChannel(textChannelWebhookUrl)\n\t.SetUsername(\"MyBot\") // username is optional.\n\t.SetContent(\"Hello WORLD\") // content is required.\n\t.ExecuteEditorCoroutine((result) =\u003e { // No need a MonoBehaviour to run.\n    \t// handle the result with callback.\n\t}));\n```\n\n\n\n### Create a post in a forum with screenshots and log files\n[UniTaskSample.cs](/src/DiscordWebhook/Assets/Samples/UniTaskSample.cs)\n```csharp\nprivate async UniTaskVoid CreateBugReportTheadToForum() {\n\tstring markdownContent = \"# Bug report from user\\nHere is the description.\\n\" + SystemInfoHelper.GetSystemInfoInMarkdownList();\n\tWebhookResponseResult result = await WebhookBuilder.CreateForum(forumWebhookUrl)\n\t\t.SetThreadName(\"TITLE\")\n\t\t.SetContent(markdownContent)\n\t\t.AddTags(forumTagIds) // Add tags to the thread. (You have to get the tag IDs by DiscordBotApi upfront.)\n\t\t.SetCaptureScreenshot(true) // capture screenshot and attach it.\n\t\t.AddFile(Application.consoleLogPath) // add log file.\n\t\t.AddFile(\"systemInfo.txt\", Encoding.UTF8.GetBytes(SystemInfoHelper.GetSystemInfoInMarkdownList())) // add system info.\n\t\t.SetCompressAllFilesToZip(true, \"LogFiles\") // compress the all files to a zip named \"LogFiles.zip\"\n\t\t.ExecuteAsync();\n\t\n\tif (result.isSuccess) {\n\t\tDebug.Log($\"Success! {result.response}\");\n\t\t\n\t\tstring url = result.GetMessageURL(serverId);\n\t\tDebug.Log(url);\n\t\tif (url != null) {\n\t\t\t// Directly open the message in the browser.\n\t\t\tApplication.OpenURL(url);\n\t\t}\n\t}\n}\n```\n\n[CoroutineSample.cs](/src/DiscordWebhook/Assets/Samples/CoroutineSample.cs)\n```csharp\nprivate void CreateBugReportTheadToForum() {\n\tstring markdownContent = \"# Bug report from user\\nHere is the description.\\n\" + SystemInfoHelper.GetSystemInfoInMarkdownList();\n\tWebhookBuilder.CreateForum(forumWebhookUrl)\n\t\t.SetThreadName(\"TITLE\")\n\t\t.SetContent(markdownContent)\n\t\t.AddTags(forumTagIds) // Add tags to the thread. (You have to get the tag IDs by DiscordBotApi upfront.)\n\t\t.SetCaptureScreenshot(true) // capture screenshot and attach it.\n\t\t.AddFile(Application.consoleLogPath) // add log file.\n\t\t.AddFile(\"systemInfo.txt\", Encoding.UTF8.GetBytes(SystemInfoHelper.GetSystemInfoInMarkdownList())) // add system info.\n\t\t.SetCompressAllFilesToZip(true, \"LogFiles\") // compress the all files to a zip named \"LogFiles.zip\"\n\t\t.ExecuteCoroutine(this, OnComplete);\n\t\n\tvoid OnComplete(WebhookResponseResult result) {\n\t\tif (result.isSuccess) {\n\t\t\tDebug.Log($\"Success! {result.response}\");\n\t\t\t\n\t\t\tstring url = result.GetMessageURL(serverId);\n\t\t\tDebug.Log(url);\n\t\t\tif (url != null) {\n\t\t\t\tApplication.OpenURL(url);\n\t\t\t}\n\t\t}\n\t}\n}\n```\n\n### Where can I find my User/Server/Message/Tag ID?\nTurn on the Developer Mode and right-click on them. \n\n(See More: https://support.discord.com/hc/en-us/articles/206346498-Where-can-I-find-my-User-Server-Message-ID)\n\nHow to find the Tag ID from forums?\n\n![](https://github.com/user-attachments/assets/f6880bb0-d732-47bf-aa52-53aefe651157)😜right-click on it.\n\n## Use Cases\n***CAVEAT: You should never directly expose your webhook token in a public product, as this poses a risk of allowing anyone to send any message through the webhook. The use cases here are either a limited scope of confidential users or implementing thier own backends to prevent from exposing the token to clients.***\n\n\u003e If you want your use case added to or removed from this list just open an [issue](https://github.com/qwe321qwe321qwe321/qwe321qwe321qwe321.github.io/issues).\n\n### [Bionic Bay](https://store.steampowered.com/app/1928690/Bionic_Bay/)\nBug reporter for the **in-house** level editor.\n\n| In-game UI | Discord |\n| ----------- | --------|\n| ![bb-ui](https://github.com/user-attachments/assets/351b2051-d0a1-4394-ac8d-7b621640262b) | ![bb-dc](https://github.com/user-attachments/assets/71f4e41b-a4fe-4a6a-83ee-362dbd53c603) |\n\n### [Minds Beneath Us](https://store.steampowered.com/app/1610440/Minds_Beneath_Us/)\nIn-game bug reporter for beta test.\n\n| In-game UI | Discord |\n| ----------- | --------|\n| \u003cvideo src=\"https://github.com/user-attachments/assets/3b589bbe-ca01-4d02-8418-27f3df014d73\"/\u003e | ![mbu-dc](https://github.com/user-attachments/assets/7a4041cc-60e6-47bd-b6ac-46ccc29ca953) |\n\n\n### [Nine Sols](https://store.steampowered.com/app/1809540/_/)\nIn-game bug reporter with their own backend.\n\n![image](https://github.com/user-attachments/assets/a1a938de-0e39-433b-b410-d09254f86bbc)\n\n### [Autopanic Zero](https://store.steampowered.com/app/1423670/_/)\nPatch notes informer in Unity Editor.\n\n![image](https://github.com/user-attachments/assets/fc628088-06b1-42cc-801a-d02cb8922f39)\n\n---\n\nI actually wrote an article that introduces the implementation of bug reports using Discord webhooks, covering its advantages and caveats, but [it's in Chinese.](https://qwe321qwe321qwe321.github.io/posts/13673/).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwe321qwe321qwe321%2Funity-discordwebhook","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fqwe321qwe321qwe321%2Funity-discordwebhook","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fqwe321qwe321qwe321%2Funity-discordwebhook/lists"}