JavaScript
Using fetch
fetch('https://nekos.best/api/v2/neko')
.then(response => response.json())
.then(json => console.log(json.results[0].url))
// https://nekos.best/api/v2/neko/0001.png
Using async
async function getNeko() {
const response = await fetch('https://nekos.best/api/v2/neko')
const json = await response.json()
console.log(json.results[0].url)
}
await getNeko()
// https://nekos.best/api/v2/neko/0001.png
Using our Wrapper
Installation
npm install nekos-best.js
| yarn add nekos-best.js
Usage
import { Client, fetchRandom } from "nekos-best.js";
// You can use the `fetchRandom()` function to fetch a random neko.
console.log(await fetchRandom("neko")); // { results: [{ artist_href: '···', artist_name: '···', source_url: '···', url: 'https://nekos.best/api/v2/neko/0247.png' }] }
// Alternatively, you can initialize a new client which offers more features.
const nekosBest = new Client();
await nekosBest.init();
// Such as the `<Client>.fetchRandom()` method.
console.log(await nekosBest.fetchRandom("neko")); // { results: [{ artist_href: '···', artist_name: '···', source_url: '···', url: 'https://nekos.best/api/v2/neko/0138.png' }] }
// You can use the `<Client>.fetchMultiple()` method to fetch multiple hug GIFs.
console.log(await nekosBest.fetchMultiple("hug", 10)); // { results: [{ artist_href: '···', artist_name: '···', source_url: '···', url: 'https://nekos.best/api/v2/hug/019.gif' }, ···] }
// Or the `<Client>.fetchFile()` method to get a single file.
console.log(await nekosBest.fetchFile("neko")); // { artist_href: '···', ···, data: <Buffer> }
Build a simple Discord Bot with discord.js
import { Client as DiscordClient } from "discord.js";
import { Client } from "nekos-best.js";
const discordClient = new DiscordClient();
const NekosBest = new Client();
await NekosBest.init();
discordClient.on("messageCreate", async (message) => {
if (message.author.bot) return;
if (message.content.startsWith('!neko')) {
message.channel.send((await NekosBest.fetchRandom("neko")).results[0].url);
}
})
discordClient.login("************************.******.***************************");
Migrate from 4.X.X
The fetchNeko(category)
function has been removed in favor of the <Client>.fetchRandom()
method and its shortcut fetchRandom()
- fetchNeko('category')
+ const nekosBest = new Client();
+
+ nekosBest.fetchRandom('category')
- fetchNeko('category')
+ fetchRandom('category')
The optional parameter amount
of the fetchNeko()
function has been removed in favor of the <Client>.fetchMultiple()
method
- fetchNeko('category', 15)
+ const nekosBest = new Client();
+
+ nekosBest.fetchMultiple('category', 15)
Other Changes
- The optional options
max
andmin
of thefetchNeko()
function have been removed
About
Created by Thunder04
The source code is available at GitHub