AnimeMangaWrapper is an npm module designed to interact with the AniList API, allowing users to search for anime and manga information. It offers dynamic features such as multilingual support (EN/FR), search by title or ID, and flexible configuration.
Ensure that Node.js is installed on your machine.
npm install anilist-api-client
In a JavaScript or TypeScript project, you can import the module as follows:
const { AnilistAPIClient } = require('anime-api-client');
import { AnilistAPIClient } from 'anime-api-client';
The module is divided into two main subclasses: Anime and Manga.
This class serves as the main interface for accessing module functionality.
Enables interaction with anime-related data.
Searches for an anime by its title.
-
Parameters:
title
(string): The title of the anime.
-
Returns:
- A promise containing the data of the found anime.
const anime = await AnilistAPIClient.anime.getByTitle('Naruto');
console.log(anime);
Searches for an anime by its ID.
-
Parameters:
id
(number): The ID of the anime.
-
Returns:
- A promise containing the data of the found anime.
const anime = await AnilistAPIClient.anime.getById(20);
console.log(anime);
Enables interaction with manga-related data.
Searches for a manga by its title.
-
Parameters:
title
(string): The title of the manga.
-
Returns:
- A promise containing the data of the found manga.
const manga = await AnilistAPIClient.manga.getByTitle('One Piece');
console.log(manga);
Searches for a manga by its ID.
-
Parameters:
id
(number): The ID of the manga.
-
Returns:
- A promise containing the data of the found manga.
const manga = await AnilistAPIClient.manga.getById(1);
console.log(manga);
The module integrates advanced error handling with clear messages.
If a missing title or ID is provided, an error is thrown:
try {
const anime = await AnilistAPIClient.anime.getByTitle('');
} catch (error) {
console.error(error.message); // "A title is required to perform a search."
}
In case of network errors or issues with the API:
try {
const manga = await AnilistAPIClient.manga.getById(9999999);
} catch (error) {
console.error(error.message); // "Error fetching data: ..."
}
Here is an example demonstrating the main features of the module:
const { AnilistAPIClient } = require('anime-api-client');
(async () => {
// Search for an anime by title
try {
const anime = await AnilistAPIClient.anime.getByTitle('Naruto');
console.log('Found anime:', anime);
} catch (error) {
console.error('Error:', error.message);
}
try {
const anime = await AnilistAPIClient.anime.getById(20);
console.log('Found anime (EN):', anime);
} catch (error) {
console.error('Error:', error.message);
}
})();
To use this module in a Discord bot, you can create a command that retrieves anime or manga information when triggered by users.
Discord bot example:
const { Client, GatewayIntentBits } = require('discord.js');
const { AnilistAPIClient } = require('anime-api-client');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;
const [command, ...args] = message.content.split(' ');
if (command === '!anime') {
const title = args.join(' ');
if (!title) {
return message.reply('Please provide the title of the anime.');
}
try {
const anime = await AnilistAPIClient.anime.getByTitle(title);
message.reply(`Found anime: ${anime.title.romaji} - ${anime.description}`);
} catch (error) {
message.reply(`Error: ${error.message}`);
}
}
if (command === '!manga') {
const title = args.join(' ');
if (!title) {
return message.reply('Please provide the title of the manga.');
}
try {
const manga = await AnilistAPIClient.manga.getByTitle(title);
message.reply(`Found manga: ${manga.title.romaji} - ${manga.description}`);
} catch (error) {
message.reply(`Error: ${error.message}`);
}
}
});
client.login('YOUR_DISCORD_BOT_TOKEN');
If you want to contribute to the module's development:
- Clone the repository:
git clone https://github.com/gonzyui/Anilist-API-Client.git
- Install dependencies:
npm install
- Build the project:
npm run build
- Run tests:
npm test
This project is licensed under the MIT License. You are free to use and modify it.