https://github.com/ryanio/discord-nft-embed-bot
A discord.js bot that listens to messages in channels and replies with items from an nft collection.
https://github.com/ryanio/discord-nft-embed-bot
Last synced: about 1 year ago
JSON representation
A discord.js bot that listens to messages in channels and replies with items from an nft collection.
- Host: GitHub
- URL: https://github.com/ryanio/discord-nft-embed-bot
- Owner: ryanio
- Created: 2021-12-17T02:04:35.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2023-12-21T02:01:02.000Z (over 2 years ago)
- Last Synced: 2025-05-07T18:05:22.341Z (about 1 year ago)
- Language: TypeScript
- Homepage:
- Size: 1.84 MB
- Stars: 12
- Watchers: 2
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# discord-nft-embed-bot
A [discord.js](https://discord.js.org/) bot that listens to messages in channels and replies with items from an nft collection.
Originally developed for [@dutchtide](https://twitter.com/dutchtide)'s [ππππππππ₯ ε€ε£ πΉπ£πππ«π](https://opensea.io/collection/midnightbreeze) collection.
An OpenSea API key is needed - create one in your account.
To run multiple instances of this bot at once check out [bot-runner](https://github.com/ryanio/bot-runner). Also check out [opensea-activity-bot](https://github.com/ryanio/opensea-activity-bot).
**Supported syntax**:
- `#1234`
- `#random` or `#rand` or `#?`
Example reply:

Example console output:
```
------------------------------------------------------------
Logged in as Dutchtide Listen Bot#8486!
Listening for messagesβ¦
------------------------------------------------------------
Message from ryanio in #π΄πview-the-breezeππ΄:
> #random
Fetching #2248β¦
Replied with #2248
------------------------------------------------------------
```
Provided metadata fields:
- Owner
- Last sale
- Listed for
- Best offer
You can add specific properties of the nft by formatting `nft.traits` and adding to the `fields` array.
## Setup
### Env
Please define the following env variables for the repository to work as intended.
#### APIs
- `DISCORD_TOKEN`
- `OPENSEA_API_TOKEN`
#### Project-specific
- `CHAIN`
- Value from [OpenSea Supported Chains](https://docs.opensea.io/reference/supported-chains). Defaults to `ethereum`.
- `TOKEN_NAME`
- `TOKEN_ADDRESS`
- `MIN_TOKEN_ID`
- `MAX_TOKEN_ID`
#### Optional
- `RANDOM_INTERVALS`
- A comma-separated list of `channelId=intervalInMinutes` e.g. `662377002338091020=5,924064011820077076=10` to send random items to channels in intervals.
- `CUSTOM_DESCRIPTION`
- A custom description for the embed. The string `{id}` is replaced with the token ID.
### Bot
To get your `DISCORD_TOKEN`, [create a Discord app](https://discord.com/developers/applications). Create a bot with the permissions: `Read Messages/View Channels`, `Send Messages`, and `Embed Links`. Then [add your bot to your server](https://discordjs.guide/preparations/adding-your-bot-to-servers.html#bot-invite-links). The bot will listen and reply to messages in all of the channels it has access to.
The `DISCORD_TOKEN` looks like this: `OTE5MzY5ODIyNzEyNzc5NzUz.YBuz2g.x1rGh4zx_XlSNj43oreukvlwsfw`
If your discord bot is not able to post messages ensure it is added to the channels you've specified and it has the permissions to `Read Messages/View Channels`, `Send Messages` and `Embed Links`, and that you have also enabled `Message Content Intent` on your bot page.
### Run
`yarn start`
#### Running on a server
My preferred setup is a $5/month Basic Droplet with Ubuntu. Install Node v16 and yarn, clone this repo, cd into it, run `yarn`, install [pm2](https://pm2.keymetrics.io/) with `yarn global add pm2`, set env vars, run `pm2 start yarn -- start`. Monitor with `pm2 list` and `pm2 logs`. Add log rotation module to keep default max 10mb of logs with `pm2 install pm2-logrotate`. To respawn after reboot, set your env vars in `/etc/profile`, then run `pm2 startup` and `pm2 save`.
You can support this repository (and get your first two months free) with the referral badge below:
[](https://www.digitalocean.com/?refcode=3f8c76216510&utm_campaign=Referral_Invite&utm_medium=Referral_Program&utm_source=badge)
##### Heroku
A `Procfile` is included for easy use.
Clone this repo, push it to heroku, set up the environment variables above, and spin up a worker with `heroku ps:scale web=0 worker=1`
Then watch the logs with `heroku logs --tail`