Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
182 changes: 99 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,118 +1,134 @@
# Python Discord Cryptocurrency Bot
# Discord Cryptocurrency Price Bot

A Discord bot that provides real-time cryptocurrency price tracking using the CoinMarketCap API.
A modern Discord bot for live cryptocurrency price updates, price alerts, and ratio/conversion tracking, powered by the CoinMarketCap API.

## Features

- **Voice Channel Price Updates**: Creates voice channels showing current prices of cryptocurrencies
- **Automatic Price Messages**: Sends regular price updates to designated text channels
- **Price Ratio Tracking**: Monitors and reports exchange rates between cryptocurrency pairs
- **Voice Channel Price Tickers:**
Dynamically creates and updates voice channels labeled with crypto symbols, prices, and movement indicators (📈/📉).
- **Scheduled Text Price Updates:**
Sends regular, clock-aligned price updates to designated text channels.
- **Ratio/Conversion Tracking:**
Tracks and posts pairwise swap/conversion rates between any two tokens.
- **Per-server Configuration:**
Each server sets its own CMC API key, roles, tickers, update channels, etc.
- **Slash Command Management:**
All admin/configuration via `/slash` commands for ease and security.
- **Exact-Timing Updates:**
Updates are precisely scheduled for :00 or :30 boundaries.

## Setup

1. Clone this repository

1. (Optional) Set up a python virtual environment: `python -m venv env`

1. (Optional) Activate the environment: `. env/bin/activate`

1. Install the code:
```
pip install .
```
## Requirements

1. Create a `.env` file in the root directory with the following variables:
- Python 3.9+
- [discord.py](https://pypi.org/project/discord/) (`discord==2.3.2`)
- [requests](https://pypi.org/project/requests/)
- [python-dotenv](https://pypi.org/project/python-dotenv/)
- [colorlog](https://pypi.org/project/colorlog/)
- A Discord Bot token ([guide](https://discord.com/developers/applications))
- A [CoinMarketCap API Key](https://coinmarketcap.com/api/)

## Installation

1. Clone this repository:
```
git clone <your-repo-url>
cd <repo-folder>
```
2. (Recommended) Setup a virtual environment:
```
python -m venv venv
. venv/bin/activate
```
3. Install dependencies:
```
pip install .
```

## Configuration

1. Create a `.env` in your root folder:
```
DISCORD_BOT_TOKEN=your_bot_token
```
*(CMC API keys are configured per-guild in Discord using the `/set_cmc_api_key` command)*

## Running the Bot

Start the bot with:

```
DISCORD_BOT_TOKEN=your_discord_bot_token
CMC_API_KEY=your_coinmarketcap_api_key
python -m bot
```

You can get a free CMC API Key [here](https://coinmarketcap.com/api/)
You'll get 10,000 free credits monthly.

1. Start the bot:
or just:
```
python -m discord_price.bot
python bot.py
```

## Configuration Commands

`/set_voice_update_category <category_id>` - Set the category for price update voice channels

`/force_update_tickers` - Force update all voice channels

`/force_update_message_tickers` - Force update all message tickers
## Usage (Slash Commands Summary)

`/force_update_ratio_tickers` - Force update all ratio tickers
> All commands are available as Discord "slash" commands (start typing `/` in your server).

`/show_settings` - Display all current bot settings
### Admin/Setup

## Voice Channel Commands
`/add_voice_ticker <ticker>` - Add a cryptocurrency ticker to voice channel updates
- `/set_cmc_api_key <api_key>` &mdash; Set your guild's CMC API key (required for price lookups)
- `/remove_cmc_api_key` &mdash; Remove CMC API key for this guild
- `/set_admin_role <role_id>` &mdash; Restrict admin commands to a role ID (optional)
- `/remove_admin_role` &mdash; Remove custom admin role (admins always allowed)

`/remove_voice_ticker <ticker>` - Remove a ticker from voice channel updates
### Voice Ticker Channels

## Message Commands
`/add_message_ticker <ticker> <channel_id>` - Add a ticker for regular price messages
- `/set_voice_update_category <category_id>` &mdash; Designate a category for voice tickers
- `/add_voice_ticker <ticker>` &mdash; Track a crypto symbol in voice
- `/remove_voice_ticker <ticker>` &mdash; Untrack a symbol in voice

`/remove_message_ticker <ticker>` - Remove a ticker from regular price messages
### Regular Message Price Updates

`/add_message_ratio_tickers <ticker1> <ticker2> <channel_id>` - Add a ticker ratio for regular messages
- `/add_message_ticker <ticker> <channel_id>` &mdash; Add a symbol to text updates in given channel
- `/remove_message_ticker <ticker>` &mdash; Remove symbol from text updates

`/remove_message_ratio_tickers <ticker1> <ticker2>` - Remove a ticker ratio from regular messages
### Ratio/Pair Tracking

## How It Works
The bot creates and updates voice channels with current cryptocurrency prices, including price movement indicators (📈 or 📉). It also sends regular messages to designated text channels with current prices and links to CoinMarketCap.
- `/add_message_ratio_tickers <ticker1> <ticker2> <channel_id>` &mdash; Add a pair (A:B) to track conversion rates
- `/remove_message_ratio_tickers <ticker1> <ticker2>` &mdash; Remove pair

Price data is automatically refreshed on the following schedule:
### Utilities

- Voice channels: Updated hourly
- `/show_settings` &mdash; Show current settings/status overview for your guild
- `/force_update_voice_tickers` &mdash; Immediately refresh all voice price channels
- `/force_update_message_tickers` &mdash; Immediately refresh all price message tickers
- `/force_update_ratio_tickers` &mdash; Immediately refresh all ratio tickers

- Text messages: Updated every 30 minutes
---

## Data Storage
The bot stores configuration data in a JSON file (crypto_bot_data.json), which includes:
## How the Bot Works

- Guild-specific settings
- **Voice Price Channels:**
At the top of each hour, all configured voice ticker channels are deleted & recreated, showing the latest price and movement.
- **Message Updates:**
Every 30 minutes, posts the current price or conversion rate to configured text channels.
- **CMC API Calls:**
CoinMarketCap API requests are live and cached, and all coin references link directly to [CMC currency pages](https://coinmarketcap.com/).
- **Data Storage:**
Per-server (guild) settings are stored in `crypto_bot_data.json`. Custom style/emoji in `crypto_bot_styles.json` (optional).
- **Security:**
Only Discord admins or those with a configured admin role can change settings.

- Voice channel tickers
---

- Message channel tickers
## Notes

- Ratio ticker pairs
- **Discord Permissions Required:**
- "View Channels", "Manage Channels" (to create/delete voice tickers)
- "Send Messages", "Embed Links" for target text channels

## Requirements
- Python 3.8+

- discord.py

- requests
- **CoinMarketCap Free API Limits:**
Each key gets 10,000 monthly credits (sufficient for most uses).

- python-dotenv
- **Customization:**
Emoji/icons can be changed via `crypto_bot_styles.json` (see the code for details).

- A Discord Bot Token

- A CoinMarketCap API Key
---

## License
MIT License


## Permissions

All Discord bots need to be granted certain permissions in the Discord
Application portal in order to operate correctly. This bot needs:

### General Permissions

* View Channels
* Manage Channels

### Text Permissions

* Send Messages
* Embed Links

### Voice Permissions

MIT License.
30 changes: 21 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,30 @@
requires = ["setuptools"]

[project]
version = "0.0.6"
name = "py_discord_price_bot"
name = "discord-crypto-price-bot"
version = "1.0.0"
description = "A Discord bot for real-time cryptocurrency price and conversion tracking with CoinMarketCap integration."
readme = "README.md"
authors = [
{name = "Daniel Chrobak", email = "danielchrobak12@gmail.com"},
{name = "Jeremy Cooper", email = "jeremy.gthb@baymoo.org"},
{ name = "Daniel Chrobak", email = "danielchrobak12@gmail.com" },
{ name = "Jeremy Cooper", email = "jeremy.gthb@baymoo.org" },
]
description = "A Discord bot posts token price updates to one or more servers."
readme = "README.md"
license = { text = "MIT" }
requires-python = ">=3.9"
license = "MIT"

dependencies = [
"discord==2.3.2",
"dotenv==0.9.9",
"requests==2.32.3",
"requests>=2.32.3",
"python-dotenv",
"colorlog",
]

[tool.setuptools.packages.find]
where = ["."]

[project.urls]
Homepage = "https://github.com/DanielChrobak/Python-Discord-Cryptocurrency-Bot"
Documentation = "https://github.com/DanielChrobak/Python-Discord-Cryptocurrency-Bot/blob/main/README.md"

[tool.setuptools]
package-dir = {"" = "."}
Loading