Hype
Hype
DIAdiscord.js - Imagine an app
Created by Hype on 7/27/2024 in #djs-questions
API help Discord.js 14
I am working on a slash command that takes all players from a link / API with name and ID of a game. These IDs are taken and inserted into another API to get the respective Elo of the player. I display these in several embeds as a ranking list, but unfortunately only a few players (10 out of 50) are displayed for clans with many players (50 players is max). I get an error code for the players that are not displayed. I think the api is overloaded/had too many requests, does anyone know if I can do anything about it in the code or is it really just due to the limited access of the API? Errors: (for each missing player)
Error fetching data for player 9243413: Error: API request failed with status 408
at C:\Users\---myname---\OneDrive\Desktop\discord-bot\commands\utility\servername_rankedlist.js:52:31
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 33)
at async Object.execute (C:\Users\---name---\OneDrive\Desktop\discord-bot\commands\utility\servername_rankedlist.js:48:35)
at async Client.<anonymous> (C:\Users\---myname---\OneDrive\Desktop\discord-bot\index.js:59:3)
Error fetching data for player 9243413: Error: API request failed with status 408
at C:\Users\---myname---\OneDrive\Desktop\discord-bot\commands\utility\servername_rankedlist.js:52:31
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Promise.all (index 33)
at async Object.execute (C:\Users\---name---\OneDrive\Desktop\discord-bot\commands\utility\servername_rankedlist.js:48:35)
at async Client.<anonymous> (C:\Users\---myname---\OneDrive\Desktop\discord-bot\index.js:59:3)
Line 48:
const playerRatings = await Promise.all(limitedPlayers.map(async (player) => {
try {
const playerResponse = await fetch(playerUrl(player.brawlhalla_id));
if (!playerResponse.ok) {
throw new Error("API request failed with status ${playerResponse.status}");
}
const playerRatings = await Promise.all(limitedPlayers.map(async (player) => {
try {
const playerResponse = await fetch(playerUrl(player.brawlhalla_id));
if (!playerResponse.ok) {
throw new Error("API request failed with status ${playerResponse.status}");
}
My code: ``````
6 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
Hi, i tried to create a SlashCommand which gets data from https://brawlhalla.fly.dev/v1/glory/id?brawlhalla_id=3145331 but idk why the slash command doesnt work. (im new to js)
const { SlashCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('glory')
.setDescription('Zeigt Informationen über einen Spieler in Brawlhalla an.')
.addIntegerOption(option =>
option.setName('brawlhalla_id')
.setDescription('Die Brawlhalla ID des Spielers')
.setRequired(true)),

async execute(interaction) {
const brawlhallaId = interaction.options.getInteger('brawlhalla_id');
const url = `https://brawlhalla.fly.dev/v1/glory/id?brawlhalla_id=${brawlhallaId}`;

try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}

const data = await response.json();


console.log(data);

await interaction.reply('Daten erfolgreich abgerufen.');
} catch (error) {
console.error('Error fetching data from Brawlhalla API:', error);
await interaction.reply('Es gab ein Problem beim Abrufen der Daten.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('glory')
.setDescription('Zeigt Informationen über einen Spieler in Brawlhalla an.')
.addIntegerOption(option =>
option.setName('brawlhalla_id')
.setDescription('Die Brawlhalla ID des Spielers')
.setRequired(true)),

async execute(interaction) {
const brawlhallaId = interaction.options.getInteger('brawlhalla_id');
const url = `https://brawlhalla.fly.dev/v1/glory/id?brawlhalla_id=${brawlhallaId}`;

try {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`API request failed with status ${response.status}`);
}

const data = await response.json();


console.log(data);

await interaction.reply('Daten erfolgreich abgerufen.');
} catch (error) {
console.error('Error fetching data from Brawlhalla API:', error);
await interaction.reply('Es gab ein Problem beim Abrufen der Daten.');
}
},
};
32 replies