Welcome, Guest. Please login or register | Contrast:

Recent Posts

Pages: [1] 2 3 ... 10
1
JS Discord Bots / Re: Parsing JSON's and Sending Data
« Last post by ThatMajesticGuy on 05 January 2018, 03:54:08 »
Oh, I didnt realize :P
2
JS Discord Bots / Re: Parsing JSON's and Sending Data
« Last post by InBlue on 05 January 2018, 01:57:55 »
Good guide, unfortunately, the forum is being moved to the wiki, wiki.codingwithstorm.com if you are interested.
3
JS Discord Bots / Parsing JSON's and Sending Data
« Last post by ThatMajesticGuy on 05 January 2018, 01:19:46 »
Hey guys! This is my first thread on here, hopefuly I can give you guys some valuable information! ;)

This topic will cover
  • Parsing JSONs
  • Sending the JSON
Requirments
  • Any HTTP interactor package. Perferably the "Got" or "Snekfetch" package (npm install got OR npm install snekfetch)
  • Any Discord.js Version, 9.0 and Above (Why would you have anything lower?)
Firstly, you will want to get your link, for this example, we will be using this: https://api.roblox.com/users/get-by-username?username=ROBLOX  To parse.

The JSON would look like this

Code: [Select]
{"Id":1,"Username":"ROBLOX","AvatarUri":null,"AvatarFinal":false,"IsOnline":false}


To have the package read it, you will want to do this

Got Version
Code: [Select]
const Discord = require('discord.js');
const bot = new Discord.Client();
const got = require('got')

bot.on("message", async message => { // We need async because there is an "await" inside the code
if (message.content === "/jsonparse") {
const res = await got("https://api.roblox.com/users/get-by-username?username=ROBLOX", {json: true}); // There is the await!
}});
Snekfetch Version
Code: [Select]
const Discord = require('discord.js')
const bot = new Discord.Client();
const snekfetch = require('snekfetch')

bot.on("message", async message => { // We need async because there is an "await" inside the code, again
if (message.content === "/jsonparse") {
const res = await snekfetch.get("https://api.roblox.com/users/get-by-username?username=ROBLOX") // There is the await, again!
}});

Its all the same from here for both the packages.

So, if you want to get the ID of ROBLOX, you would just need to do this simple thing,

Code: [Select]
message.channel.send(res.body.Id)

It is that simple, then it would send 1! (1 is ROBLOX's ID)

But what if there is an "Array" in the JSON? Well I will cover that in this link: https://dog-api.kinduff.com/api/facts

The JSON would look like:
Code: [Select]
{"facts":["Your Fact."],"success":true}

Code:
Code: [Select]
  const res = await got("https://dog-api.kinduff.com/api/facts", {json: true})
  const res = await snekfetch("https://dog-api.kinduff.com/api/facts")
  message.channel.send(`Did you know?\n**__${res.body.facts[0]}__**`) // When there is only 1 object in the array, you would put 0, if there are 2 objects in an array and you want the second one, you would do  res.body.whatchamaycallit[1], so on so forth

Full Code:
Code: [Select]
const Discord = require('discord.js')
const bot = new Discord.Client();

// Got
const got = require('got')

bot.on("message", async message => {
if (message.content === "/jsonparse") {
const res = await got("https://api.roblox.com/users/get-by-username?username=ROBLOX", {json: true});
message.channel.send(res.body.Id)
}});

// Snekfetch
const snekfetch = require('snekfetch')

bot.on("message", async message => {
if (message.content === "/jsonparse") {
const res = await snekfetch.get("https://api.roblox.com/users/get-by-username?username=ROBLOX")
message.channel.send(res.body.Id)
}});
Well, That covers the basics of JSON Parsing, hope you learned something. Hopefully I will post more soon.  :thankyou:

4
JS Discord Bots / Re: Hosting your Discord Bot
« Last post by ThatMajesticGuy on 05 January 2018, 00:19:59 »
Heroku is an absolutely awful choice for bot hosting. There's no such thing as free and at least acceptable at the same time.
To be fair, its probably the best free hosting service out there... Its good to start with, until you can make money off the bot, stick with it, its better than nothing
5
C# Discord Bots / Re: [v1.0] Play audio from YT or local file
« Last post by Lost on 03 December 2017, 20:18:27 »
Hello!

So I've been writing out the code and to cut to the chase it says that 'VideoInfo' basically doesn't exist, I've tried all other directories of 'youtubeExplode' but no luck.
6
C# Discord Bots / Re: [v1.0] Embedding [1/3]: Bot info
« Last post by RaythMistwalker on 24 November 2017, 22:22:50 »
What are you importing to use "GetHeapSize" ?
7
JS Discord Bots / Re: [Discord v11/v11.1.0] Eval
« Last post by Cecemel_PvP on 22 November 2017, 15:23:22 »
By me the messages spam so hard
8
Java Script / Re: Pls help
« Last post by Cecemel_PvP on 22 November 2017, 07:32:40 »
I dont find what I want...
9
Java Script / Re: Pls help
« Last post by Cecemel_PvP on 21 November 2017, 22:10:36 »
Thanks ^^
10
Java Script / Re: Pls help
« Last post by jtsshieh on 21 November 2017, 22:09:23 »
You can look through the threads and tutorials over here: https://forum.codingwithstorm.com/index.php?board=52.0


Those are all discord.js related and see what you can find.


Happy coding c;
Pages: [1] 2 3 ... 10