Hype
Hype
DIAdiscord.js - Imagine an app
Created by Hype on 7/27/2024 in #djs-questions
API help Discord.js 14
alr
6 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/27/2024 in #djs-questions
API help Discord.js 14
everything up2date
6 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/27/2024 in #djs-questions
API help Discord.js 14
my code:




6 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
Had the same Problem with my first command, but fixed it and now i have the same Problem again
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
Theres no error, the command handler wont register the command
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
im too stupid to understand that
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
{
"statusCode": 200,
"message": "barbarbar338 from database",
"data": {
"brawlhalla_id": 3145331,
"name": "barbarbar338",
"bestElo": 1865,
"eloReset": 1680,
"glory": {
"wins": 300,
"rating": 3792
},
"lastSynced": 1721253293077
}
}
{
"statusCode": 200,
"message": "barbarbar338 from database",
"data": {
"brawlhalla_id": 3145331,
"name": "barbarbar338",
"bestElo": 1865,
"eloReset": 1680,
"glory": {
"wins": 300,
"rating": 3792
},
"lastSynced": 1721253293077
}
}
and the data from my new command like that
{
"statusCode": 200,
"message": "barbarbar338 synced",
"data": {
"name": "barbarbar338",
"brawlhalla_id": 3145331,
"rating": 1833,
"peak_rating": 1865,
"tier": "Platinum 3",
"wins": 13,
"games": 22,
"region": "EU",
"global_rank": 0,
"region_rank": 0,
"legends": [
{
"legend_id": 3,
"legend_name_key": "bodvar",
"rating": 752,
"peak_rating": 0,
"tier": "Tin 1",
"wins": 0,
"games": 0
},
{
"legend_id": 4,
"legend_name_key": "cassidy",
"rating": 756,
"peak_rating": 0,
"tier": "Tin 1",
"wins": 0,
"games": 0
},...........
{
"statusCode": 200,
"message": "barbarbar338 synced",
"data": {
"name": "barbarbar338",
"brawlhalla_id": 3145331,
"rating": 1833,
"peak_rating": 1865,
"tier": "Platinum 3",
"wins": 13,
"games": 22,
"region": "EU",
"global_rank": 0,
"region_rank": 0,
"legends": [
{
"legend_id": 3,
"legend_name_key": "bodvar",
"rating": 752,
"peak_rating": 0,
"tier": "Tin 1",
"wins": 0,
"games": 0
},
{
"legend_id": 4,
"legend_name_key": "cassidy",
"rating": 756,
"peak_rating": 0,
"tier": "Tin 1",
"wins": 0,
"games": 0
},...........
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
nvm, new problem, i updated the handler with recursive. i added a 2nd command with same nearly same api usage.
const { SlashCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('stats')
.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) {
await interaction.deferReply(); // Den Befehl zunächst als "ausgeführt" markieren

const brawlhallaId = interaction.options.getInteger('brawlhalla_id');
const url = `https://brawlhalla.fly.dev/v1/ranked/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();

// Verarbeite die Daten und sende die Antwort an Discord
const playerName = data.data.name;
const peakRating = data.data.peak_rating;

await interaction.editReply(`Das Peak Rating von Spieler ${playerName} beträgt: ${peakRating}`);
} catch (error) {
console.error('Error fetching data from Brawlhalla API:', error);
await interaction.editReply('Es gab ein Problem beim Abrufen der Daten.');
}
},
};
const { SlashCommandBuilder } = require('@discordjs/builders');
const fetch = require('node-fetch');

module.exports = {
data: new SlashCommandBuilder()
.setName('stats')
.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) {
await interaction.deferReply(); // Den Befehl zunächst als "ausgeführt" markieren

const brawlhallaId = interaction.options.getInteger('brawlhalla_id');
const url = `https://brawlhalla.fly.dev/v1/ranked/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();

// Verarbeite die Daten und sende die Antwort an Discord
const playerName = data.data.name;
const peakRating = data.data.peak_rating;

await interaction.editReply(`Das Peak Rating von Spieler ${playerName} beträgt: ${peakRating}`);
} catch (error) {
console.error('Error fetching data from Brawlhalla API:', error);
await interaction.editReply('Es gab ein Problem beim Abrufen der Daten.');
}
},
};
And ive the same problem "No command matching stats was found." i dont understand why its the same problem and why stats is not working but my other command from the top is. the data from my first command looks like that
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
@rmHawk765 tysm, it worked ❤️
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
alr ty
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
anyone else with advice? 🙂
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
No description
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

client.login(token);
client.on(Events.InteractionCreate, async interaction => {
if (!interaction.isChatInputCommand()) return;
const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});

client.login(token);
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
index.js
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

const express = require('express');
const { port } = require('./config.json');

const app = express();

app.get('/', (request, response) => {
return response.sendFile('index.html', { root: '.' });
});

app.listen(port, () => console.log(`App listening at http://localhost:${port}`));

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
const fs = require('node:fs');
const path = require('node:path');
const { Client, Collection, Events, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });

client.commands = new Collection();
const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

const express = require('express');
const { port } = require('./config.json');

const app = express();

app.get('/', (request, response) => {
return response.sendFile('index.html', { root: '.' });
});

app.listen(port, () => console.log(`App listening at http://localhost:${port}`));

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

client.once(Events.ClientReady, readyClient => {
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
});
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
deploy-commands.js
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('fs');
const path = require('path');

const commands = [];

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);

if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(`Error refreshing application (/) commands: ${error.message}`);
}
})();
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
const fs = require('fs');
const path = require('path');

const commands = [];

const foldersPath = path.join(__dirname, 'commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);

if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(`Error refreshing application (/) commands: ${error.message}`);
}
})();
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
theres no full error stack, thats the only output, or im too stupid to find it. xd
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
im gonna try that ty
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
console is saying "No command matching glory was found."xd
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
not responding*
32 replies
DIAdiscord.js - Imagine an app
Created by Hype on 7/17/2024 in #djs-questions
Slashcommands with API
forgot to send mb
32 replies