{"id":18084531,"url":"https://github.com/endel/discord-webgame-toolkit","last_synced_at":"2025-09-13T01:13:20.394Z","repository":{"id":94803945,"uuid":"353193905","full_name":"endel/discord-webgame-toolkit","owner":"endel","description":"Discord Web Auth for Games + Bot","archived":false,"fork":false,"pushed_at":"2022-02-13T14:55:51.000Z","size":6851,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T20:09:18.938Z","etag":null,"topics":["discord","discord-bot","discord-js","discord-js-example"],"latest_commit_sha":null,"homepage":"https://gamestd.io/discord-webgame-toolkit","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/endel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null},"funding":{"github":"endel","patreon":"endel","open_collective":null,"ko_fi":"endeld","tidelift":null,"custom":"https://www.paypal.me/endeld"}},"created_at":"2021-03-31T01:55:22.000Z","updated_at":"2024-06-14T05:14:31.000Z","dependencies_parsed_at":"2023-05-09T17:45:45.278Z","dependency_job_id":null,"html_url":"https://github.com/endel/discord-webgame-toolkit","commit_stats":null,"previous_names":["endel/discord-webgame-toolkit"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/endel/discord-webgame-toolkit","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2Fdiscord-webgame-toolkit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2Fdiscord-webgame-toolkit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2Fdiscord-webgame-toolkit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2Fdiscord-webgame-toolkit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/endel","download_url":"https://codeload.github.com/endel/discord-webgame-toolkit/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/endel%2Fdiscord-webgame-toolkit/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263061406,"owners_count":23407606,"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","discord-bot","discord-js","discord-js-example"],"created_at":"2024-10-31T15:07:05.330Z","updated_at":"2025-07-02T02:07:15.567Z","avatar_url":"https://github.com/endel.png","language":"TypeScript","funding_links":["https://github.com/sponsors/endel","https://patreon.com/endel","https://ko-fi.com/endeld","https://www.paypal.me/endeld"],"categories":[],"sub_categories":[],"readme":"# Discord Web Game Toolkit\n\nThe code on this repository is a Node.js application that you can either copy the files over to your existing Node.js application, or build your own stuff on top of it. You should deploy this code on your own server in order to have it working for your game.\n\n\u003cimg src=\"images/discord-auth.png\" width=\"30%\" align=\"left\" /\u003e\n\u003cimg src=\"images/discord-bot-demo.png\" width=\"63%\" /\u003e\n\n**What's included here?**\n\n- Discord OAuth Integration\n- Discord Bot with a `!profile` command to output the player's profile.\n- Express routes to authenticate with Discord\n- A `User` model with default properties, and a database setup. You can add more models as you need.\n\n**Node modules in use:**\n- [MikroORM](https://www.npmjs.com/package/@mikro-orm/core) + [MongoDB](https://www.npmjs.com/package/mongodb) for database access.\n- [Grant](https://www.npmjs.com/package/grant) for OAuth integration. Only Discord is being used, but you can easily use more providers such as Google, Twitter, etc.\n- [Express](https://www.npmjs.com/package/express) for binding Grant routes, and custom login.\n- [JsonWebToken](https://www.npmjs.com/package/jsonwebtoken) for encrypting and exposing a token containing the `discord_id` for the client-side.\n- [Discord.js](https://www.npmjs.com/package/discord.js) for Discord Bot integration.\n\n\u003ca href=\"https://gamestd.io\"\u003e\u003cimg src=\"https://gamestd.io/sponsored-by.png\" width=\"200\" /\u003e\u003c/a\u003e\n\n# Setup Instructions\n\n## Setting up your local environment\n\n- [Download and install Node.js v14](https://nodejs.org/en/)\n- [Download and install MongoDB Community Edition](https://www.mongodb.com/try/download/community)\n- [Download and install Visual Studio Code](https://code.visualstudio.com/) (or other editor of your choice)\n\nTo run the project locally, open the folder of this package on your terminal, and run the following commands:\n\n```\nnpm install\nnpm start\n```\n\nYou should see the following logs:\n\n```\n\u003e discord-webgame-toolkit@1.0.0 start\n\u003e ts-node-dev src/index.ts\n\n[INFO] 13:07:50 ts-node-dev ver. 1.1.6 (using ts-node ver. 9.1.1, typescript ver. 4.1.3)\n[discovery] ORM entity discovery started, using ReflectMetadataProvider\n[discovery] - processing entity User\n[discovery] - processing entity BaseEntity\n[discovery] - entity discovery finished, found 2 entities, took 16 ms\n[info] MikroORM successfully connected to database discord_webgame_toolkit on mongodb://localhost:27017\nDatabase connected.\nListening on ws://localhost:3000\nApplication v1.0.0 ready.\nDiscord bot logged in as Webgame Toolkit#3978!\n```\n\n## Discord Authentication\n\nGo to [https://discord.com/developers/applications](https://discord.com/developers/applications) and click on \"New Application\".\n\n![Click on New Application](images/discord-new-application.png)\n\nAfter having your application created, you need to copy both your **CLIENT ID** and **CLIENT SECRET**, and paste it into the `.env` file.\n\n![Client and Secret](images/discord-application-id.png)\n\nIn the `.env` file, these values will look like this:\n\n```\nDISCORD_CLIENT_ID=790647592480276541\nDISCORD_CLIENT_SECRET=20fgvLavtsc87sMXYdV6ETeSI92LwP8m\n```\n\nAdd OAuth Redirect to all possible deployments of your game. You should have at least two entries here:\n\n![OAuth Redirects](images/discord-oauth-redirects.png)\n\n- `http://localhost:3000/connect/discord/callback`: For testing locally.\n- `http://yourgame.io/connect/discord/callback`: For the live game (replace `yourgame.io` to where your game is deployed remotely!)\n\n## Discord bot\n\nNow let's create the bot for your Discord application:\n\n![Add Bot](images/discord-bot-add.png)\n\nCopy the \"token\" of your bot, and paste it into the `.env` file as well.\n\n![Add Bot](images/discord-bot-token.png)\n\nIn the `.env` file, the token will look like this:\n\n```\nDISCORD_BOT_TOKEN=NzkwNjQ3NTkyNDgwMjc2NTQx.X-Dp8w.hBQGt-ioJKvaIgdWp0NPFRPIa-w\n```\n\n## Adding the bot to your server\n\nThe last step is to add the bot into your server.\n\n1. Select \"OAuth\" in the sidebar.\n2. In the \"OAuth2 URL Generator\", under \"scopes\" - select \"bot\".\n3. Under \"Bot permissions\", select \"Send Messages\", and \"Embed links\". You may select more options if you are going to implement more features on your own!\n\n![Add Bot To Your Server](images/discord-oauth-addbot.png)\n\nNow, click on \"Copy\" in the authorization URL, and open it in your browser. You will be asked to select the server the bot is going to join:\n\n![Add Bot To Your Server](images/discord-oauth-addbot-authorize.png)\n\nYou're done! Have fun making custom bot actions for your game!\n\n# Modifying the source-code\n\nThe source-code on this repository is very simple, and should be easily exchangeable if you'd like to move it over to an existing project.\n\n## MikroORM and the `User` model\n\nMikroORM is an object–relational mapping that supports multiple database engines. On the current set-up, this project uses MongoDB, as you can see on `src/config/mikro-orm.config.ts`:\n\n```typescript\n// ...\nconst options: Options = {\n  type: 'mongo',\n  entities: [User, BaseEntity],\n  dbName: 'discord_webgame_toolkit',\n// ...\n```\n\n[See MikroORM documentation](https://mikro-orm.io/docs/installation) if you'd like to use a different database engine.\n\nYou can add as many properties as you need in the `User` model located at `src/models/User.ts`. You could have a field to keep track of each user's highscores, for example, and more game-specific stats.\n\nTo perform operations in your `User` model, MikroORM requires you to access it from its respective [EntityRepository](https://mikro-orm.io/docs/repositories-api) instance:\n\n\n```typescript\nimport { DI } from \"../config/database.config\";\n\nlet user = await DI.userRepository.findOne({ name: /endel/i });\n```\n\n## The Discord Bot logic\n\nYou can find the Discord Bot logic at `src/config/discord-bot.config.ts`. The discord.js API is quite extensive and is very versatile. You can see the full documentation of its capabilities at [discord.js.org](https://discord.js.org/#/docs/).\n\n## Deployment\n\nAfter you deploy this on your own server, make sure to update the `BACKEND_URL` in your `.env` file. This step is fundamental due to the way OAuth handle redirects internally.\n\n```\nBACKEND_URL=https://gamestd.io\n```\n\nAbove is a real-world example of how this is currently set-up for the [public demo](https://endel.dev/discord-webgame-toolkit).\n\n# Community\n\n\u003ca href=\"https://discord.gg/dqTw2cKrAe\"\u003eJoin the Discord Test server.\u003c/a\u003e\n\n# License\n\nCopyright © Endel Dreyer. See [LICENSE.md](LICENSE.md) for more details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendel%2Fdiscord-webgame-toolkit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fendel%2Fdiscord-webgame-toolkit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fendel%2Fdiscord-webgame-toolkit/lists"}