/cf-chart-img-discord-bot

A simple Discord Bot based on CHART-IMG API with serverless Cloudflare Workers.

Primary LanguageJavaScript

CHART-IMG DISCORD BOT

It is a simple Discord bot based on CHART-IMG API with serverless Cloudflare Workers. It supports all public TradingView symbols, and the preset symbols can be customized by modifying the file config.json.

Live Discord Bot

Invite Link

You are welcome to use this bot if you don't want to customize your own. It will always run with the latest version.

Features

Slash Commands

Slash Commands are the new, exciting way to interact with bots on Discord. With Slash Commands, all you have to do is type / and you're ready to use your preset commands.

general_info general_info general_info

Main slash commands

  • /invite
  • /price query
  • /chart query

Preset slash commands

You can customize the commands by modifying config.json.

  • /price crypto
  • /price stock
  • /price forex
  • /chart query
  • /chart crypto
  • /chart stock
  • /chart forex

Requirement

Setup

Wrangler Install & Login

To install wrangler, ensure you have npm installed, preferably using a Node version manager like Volta or nvm to avoid permission issues or to easily change Node.js versions, then run:

$ npm install -g wrangler
$ wrangler login

Create Discord Bot

To start, you need to create a discord app through the Discord Developer Dashboard:

  • Visit https://discord.com/developers/applications

  • Click New Application, and choose a name

  • Copy your Application ID and Public Key, and put them in the file wrangler.toml.

  • Now click on the Bot tab on the left sidebar, and create a bot! You can choose the same name as your app.

  • Grab the token for your bot, and store it somewhere safe. (For security reasons, you can only view your bot token once. If you misplace your token, you'll have to generate a new one.)

wrangler.toml

[env.production.vars]
DISCORD_APPLICATION_ID = "YOUR_DISCORD_APPLICATION_ID"
DISCORD_PUBLIC_KEY = "YOUR_DISCORD_PUBLIC_KEY"

Environment Variable

Create secret environment variables using wrangler secret.

wrangler secret put DISCORD_TOKEN --env production

$ wrangler secret put DISCORD_TOKEN --env production
 ⛅️ wrangler 2.0.15
--------------------
Enter a secret value: ****************************************
🌀 Creating the secret for script chart-img-discord-bot-production
✨ Success! Uploaded secret DISCORD_TOKEN

wrangler secret put CHART_IMG_API_KEY --env production

$ wrangler secret put CHART_IMG_API_KEY --env production
 ⛅️ wrangler 2.0.15
--------------------
Enter a secret value: ****************************************
🌀 Creating the secret for script chart-img-discord-bot-production
✨ Success! Uploaded secret CHART_IMG_API_KEY

Deploy

Register Slash Commands

Register Discord slash commands.

npm run setup:production

$ npm run setup:production

> cf-chart-img-discord-bot@0.1.0 setup:production
> node src/setup.js --env production

? Enter DISCORD_TOKEN secret value :  [input is hidden]

Publish Cloudflare Worker

Publish your Cloudflare Worker and get a invoke URL.

npm run deploy:production

$ npm run publish:production

> cf-chart-img-discord-bot@0.1.0 publish:production
> wrangler publish --env production

 ⛅️ wrangler 2.0.15
--------------------
▲ [WARNING] Enabling node.js compatibility mode for built-ins and globals. This is experimental and has serious tradeoffs.
  Please see https://github.com/ionic-team/rollup-plugin-node-polyfills/ for more details.


Your worker has access to the following bindings:
- Vars:
  - DEBUG: "false"
  - DISCORD_APPLICATION_ID: "YOUR_DISCORD_APPLICATION_ID"
  - DISCORD_PUBLIC_KEY: "YOUR_DISCORD_PUBLIC_KEY..."
Total Upload: 215.95 KiB / gzip: 42.86 KiB
Uploaded chart-img-discord-bot-production (1.85 sec)
Published chart-img-discord-bot-production (0.22 sec)
  chart-img-discord-bot-production.YOUR_ID.workers.dev

Set Discord Interactions Endpoint URL

Set your Interactions Endpoint URL https://chart-img-discord-bot-production.YOUR_ID.workers.dev from the previous step.

general_info

Invite URL Generator

invite_url