Skip to content

ryanio/discord-nft-embed-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

78 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

discord-nft-embed-bot

A discord.js bot that listens to messages in channels and replies with items from an nft collection.

Originally developed for @dutchtide's 𝕄𝕚𝕕𝕟𝕚𝕘𝕙𝕥 夏季 𝔹𝕣𝕖𝕖𝕫𝕖 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. Also check out opensea-activity-bot.

Supported syntax:

  • #1234
  • #random or #rand or #?

Example reply:

Example bot 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

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. Create a bot with the permissions: Read Messages/View Channels, Send Messages, and Embed Links. Then add your bot to your server. 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 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:

DigitalOcean Referral 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

About

A discord.js bot that listens to messages in channels and replies with items from an nft collection.

Resources

Stars

Watchers

Forks