Slashcommands with API
Hi, i tried to create a SlashCommand which gets data from 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.');
}
},
};