Search the Community
Showing results for tags 'discord bot'.
-
A basic example of a Discord.js bot that can autoupdate every 5 seconds based on an API using fetch. Install nodejs and some packages. Linux x64 or ARM, example below is 64-bit. wget https://nodejs.org/dist/v16.0.0/node-v16.0.0-linux-x64.tar.xz tar xvf node-v16.0.0-linux-x64.tar.xz cd node-v16.0.0-linux-x64/ sudo cp -R bin/* /usr/bin/ sudo cp -R lib/* /usr/lib/ npm install discord.js npm install node-fetch blockheight.js https://gist.github.com/buzzkillb/63a66f27ff65c6dd880a6c3eae740602 //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, block height console.log(data); var blockHeight = "Height: " + data guild.me.setNickname(blockHeight); }) }, 5000); }); client.login(config.BOT_TOKEN); config.json { "BOT_TOKEN": "DISCORDGENERATEDTOKENGOESHERE" } How to add the bot to a server and get your BOT_TOKEN Authorizing Discord User Visit https://discord.com/developers/applications and create 'New Application'. Set a bot name like BlockHead On the page that follows, set the account name and save. Then click Bot Create a Bot account and Save. Click 'Copy' on the Token; this is the API Key you use in the bot script Visit the OAuth2 tab. Under Scopes, select 'bot' The resulting URL is what you (or anyone) use to add your bot instance to a server.
- 2 replies
-
- nodejs
- javascript
-
(and 1 more)
Tagged with: