Coder Social home page Coder Social logo

discord-bot-cloudflare-slash's Introduction

/create with Cloudflare Workers

A slash-create template, using Cloudflare Workers. Based off of Snazzah/slash-create-worker, but with a Github Actions workflow to automatically deploy (the repository serves as a single source of truth).

Commands are synced to Discord on every push using Snazzah/slash-up and bot code is deployed to Cloudflare using cloudflare/wrangler-action

Getting Started

After using this template, update the project name in wrangler.toml (and package.json). This name will be used for your project deployment in the Cloudflare dashboard and in your worker URL.

Create a Discord application with a bot user at https://discord.com/developers/applications (see https://discord.com/developers/docs/tutorials/hosting-on-cloudflare-workers).

Install dependencies using pnpm 8:

pnpm install

Upload repository secrets to the Github dashboard:

CLOUDFLARE_ACCOUNT_ID
CLOUDFLARE_API_TOKEN

DISCORD_APP_ID
DISCORD_PUBLIC_KEY
DISCORD_BOT_TOKEN

# optional
DEVELOPMENT_GUILD_ID

Once you have deployed your worker, go to the "general information" page of your discord application and set its interactions endpoint URL to the Cloudflare worker URL, e.g. https://discord-bot-cloudflare-slash.your-subdomain.workers.dev.

Note: When you create a command, make sure to include it in the array of commands in ./src/commands/index.ts.

Local Development

For faster development without deploying each change, you may run the bot code on your local machine using wrangler and connect it to Discord using a free ngrok tunnel. Run wrangler login and follow the prompts to login to your Cloudflare account, and copy .env.example to .dev.vars and fill in the secrets.

Open three terminals: one for pnpm dev, one for pnpm ngrok, and one for running pnpm sync:dev each time you change a command's metadata (name, options, etc). Go to the "general information" page of your discord application and set its interactions endpoint URL to the ngrok tunnel.

Using DEVELOPMENT_GUILD_ID and testing in a single server is recommended, as server-specific commands sync instantly, while a bot's commands that can be used in any server update with a 1 hour cooldown/delay.


This work is marked with CC0 1.0 Universal.

discord-bot-cloudflare-slash's People

Contributors

marcustyphoon avatar dependabot[bot] avatar

Watchers

 avatar

discord-bot-cloudflare-slash's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.