Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
discord_blockheight.js
//npm install discord.js node-fetch
//get blockheight from Chainz CryptoID and update Bots Name as Blockheight
const Discord = require('discord.js');
const fetch = require('node-fetch');
const config = require("./config.json");
var chainzApi = "https://chainz.cryptoid.info/d/api.dws?q=getblockcount"
const client = new Discord.Client();
client.on('ready', async () => {
client.user.setActivity('denarius.io');
const GUILD_ID = client.guilds.cache.map(guild => guild.id);
const guild = await client.guilds.fetch(GUILD_ID);
console.log('Bot is connected...');
setInterval(async function(){
fetch(chainzApi)
.then(function (response) {
// Get a JSON object from the response
// This is a weird quirk of Fetch
return response.json();
}).then(function (data) {
// Log the data to the console, Total balance of Token
console.log(data);
var blockHeight = "Height: " + data
guild.me.setNickname(blockHeight);
})
}, 5000);
});
client.login(config.BOT_TOKEN);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment