Kubi
Kubi
Explore posts from servers
DIAdiscord.js - Imagine a boo! 👻
Created by Kubi on 11/29/2023 in #djs-questions
What is the max time for a Collect Interaction?
No description
8 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Kubi on 7/11/2023 in #djs-questions
errorhandler
2 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Kubi on 6/23/2023 in #djs-questions
Markdown in embeds broken?
11 replies
DIAdiscord.js - Imagine a boo! 👻
Created by Kubi on 6/23/2023 in #djs-questions
Interaction Failed Async
Hello! i have no clue how to await an interaction in V14, but after trying, the code that is attached is what i came with. however, it's simply not updating the interaction, nor is it printing my console logs which is causing me so much confusion notlikethis anyone that could point me to the right direction (no docs please, I've already read it like 4 times, and i'm understanding less the more I read it)
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const axios = require('axios');

async function fetchAndSortEvents() {
let options = {
method: "POST",
url: "<Definitely not a Link placeholder>",
headers: {
cookie: "<Nom Nom Cookies>",
"content-type": "application/json"
},
data: {
query: "<Yay a Query>",
variables: null,
operationName: "Events"
}
};

try {
const response = await axios.request(options);
const events = response.data.data.events;
events.sort((a, b) => b.id - a.id);
return events;
} catch (error) {
console.error(error);
}
}

function displayEvents(events, startIndex, endIndex) {
let result = 'Event ID | Event Name\n';
for (let i = startIndex; i < endIndex; i++) {
result += `${events[i].id} | ${events[i].displayName}\n`;
}
return result;
}

module.exports = {
data: new SlashCommandBuilder()
.setName('arenagamesfetch')
.setDescription('Fetches and displays the latest 10 Arena Games events'),
async execute(interaction) {
const events = await fetchAndSortEvents();
let startIndex = 0;
let endIndex = 10;

const result = displayEvents(events, startIndex, endIndex);
const embed = new EmbedBuilder()
.setTitle('Latest Arena Games Events')
.setThumbnail('<Thumbnail Link>')
.setDescription(result);


const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('listPrev')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('listNext')
.setLabel('Next')
.setStyle(ButtonStyle.Primary),
);

await interaction.reply({ embeds: [embed], components: [row] });

const filter = i => i.customId === 'previous' || i.customId === 'next';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async i => {
try {
if (i.customId === 'listPrev') {
startIndex -= 10;
endIndex -= 10;
if (startIndex < 0) startIndex = 0;
if (endIndex < 10) endIndex = 10;
console.error("Previoused");
} else if (i.customId === 'listNext') {
startIndex += 10;
endIndex += 10;
if (startIndex > events.length - 1) startIndex = events.length - 1;
if (endIndex > events.length) endIndex = events.length;
console.error("Nexted");
}
} catch (error) {
console.error(error);
}


const result = displayEvents(events, startIndex, endIndex);
embed.setDescription(result);
await i.update({ embeds: [embed], components: [row] });
});
},
};
const { SlashCommandBuilder, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle } = require('discord.js');
const axios = require('axios');

async function fetchAndSortEvents() {
let options = {
method: "POST",
url: "<Definitely not a Link placeholder>",
headers: {
cookie: "<Nom Nom Cookies>",
"content-type": "application/json"
},
data: {
query: "<Yay a Query>",
variables: null,
operationName: "Events"
}
};

try {
const response = await axios.request(options);
const events = response.data.data.events;
events.sort((a, b) => b.id - a.id);
return events;
} catch (error) {
console.error(error);
}
}

function displayEvents(events, startIndex, endIndex) {
let result = 'Event ID | Event Name\n';
for (let i = startIndex; i < endIndex; i++) {
result += `${events[i].id} | ${events[i].displayName}\n`;
}
return result;
}

module.exports = {
data: new SlashCommandBuilder()
.setName('arenagamesfetch')
.setDescription('Fetches and displays the latest 10 Arena Games events'),
async execute(interaction) {
const events = await fetchAndSortEvents();
let startIndex = 0;
let endIndex = 10;

const result = displayEvents(events, startIndex, endIndex);
const embed = new EmbedBuilder()
.setTitle('Latest Arena Games Events')
.setThumbnail('<Thumbnail Link>')
.setDescription(result);


const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('listPrev')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId('listNext')
.setLabel('Next')
.setStyle(ButtonStyle.Primary),
);

await interaction.reply({ embeds: [embed], components: [row] });

const filter = i => i.customId === 'previous' || i.customId === 'next';
const collector = interaction.channel.createMessageComponentCollector({ filter, time: 15000 });

collector.on('collect', async i => {
try {
if (i.customId === 'listPrev') {
startIndex -= 10;
endIndex -= 10;
if (startIndex < 0) startIndex = 0;
if (endIndex < 10) endIndex = 10;
console.error("Previoused");
} else if (i.customId === 'listNext') {
startIndex += 10;
endIndex += 10;
if (startIndex > events.length - 1) startIndex = events.length - 1;
if (endIndex > events.length) endIndex = events.length;
console.error("Nexted");
}
} catch (error) {
console.error(error);
}


const result = displayEvents(events, startIndex, endIndex);
embed.setDescription(result);
await i.update({ embeds: [embed], components: [row] });
});
},
};
23 replies