Skip to main content

🎥 How to Create a Discord bot for NFT Transfers with the QuickAlerts UI

Updated on
Dec 14, 2023

1 min read

In this video, our friend Hashlips demonstrates how to create a bot to get real-time NFT Transfer notifications in Discord with the help of QuickAlerts, Node.js, and Discord.js.
Subscribe to our YouTube channel for more videos!

The following code example includes the QuickAlerts expression for Sketchy Ape Book Club NFT Transfers, as seen in the video. In your deployment, replace the tx_logs_address with the address of the NFT contract you want to monitor.

Expression
Deploy
1
tx_logs_address == '0xaDC28cac9c1d53cC7457b11CC9423903dc09DDDc'

The tx_from part of the expression shown in the video has been removed from the example above, as it is not necessary unless you only want your bot to send messages when a particular wallet sends the NFTs.

Following are the code files shown in the video.

index.js
const Discord = require('discord.js');
const dotenv = require('dotenv');
const express = require('express');

dotenv.config();

const app = express();
const port = process.env.PORT || 3000;
const webhookClient = new Discord.WebhookClient({
url: process.env.WEBHOOK_URL,
});

app.use(express.json());

app.get('/', (req, res) => {
res.send('Welcome');
});

app.post('/', (req, res) => {
const bodyData = req.body;

webhookClient.send(
'Wow looks like address ${
bodyData[0].from
} just transferred token ID: ${Number.parseInt(
bodyData[0].logs[0].topics.[3],
16
)}
});

console.log(json.stringify(bodyData));

res.send(json.stringify(bodyData));
});

app.listen(port, () => {console.log('Server is running');});
Procfile
web: node index.js
.env
WEBHOOK_URL=your-discord-webhook-url

We ❤️ Feedback!

Let us know if you have any feedback or requests for new topics. We'd love to hear from you.

Share this guide