Xu Xiaolan
Xu Xiaolan
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 9/1/2023 in #djs-questions
Button callback not working
i had this button function that used to work properly, now that im checking in after a while of refactoring it just doesnt work anymore and i have not the slightest clue why.
12 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 8/21/2023 in #djs-questions
getting message.author esque information
8 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 6/13/2023 in #djs-questions
disable select menu
I was told i cant do it but I just wanna ask here to make sure, am i able to disable an option in a select menu?
9 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 6/4/2023 in #djs-questions
disabling an interaction menu
im just trying to disable an interaction after input from a player so that the messages can be properly deleted
43 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 5/21/2023 in #djs-questions
encyclopedia embed type thing
hey so i was trying to make a dex or enc for my bot's items and i keep getting this one error: Uncaught DiscordAPIError DiscordAPIError[50035]: Invalid Form Body embeds[0].description[BASE_TYPE_REQUIRED]: This field is required at handleErrors (c:\Users\Moh\Desktop\clutter\Gacha-Bot\bot-20\Tater\node_modules@discordjs\rest\dist\index.js:640:13) at processTicksAndRejections (internal/process/task_queues:95:5) here is any relevant code:
const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');

async function menuButtons(discordId, message, time, embeds, startPage) {
let page = startPage;

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setEmoji('◀️'),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setEmoji('▶️'),
new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete')
.setStyle(ButtonStyle.Danger)
.setEmoji('🗑️'),
);

const pageEmbed = await message.channel.send({ embeds: [embeds[page]], components: [row] });

const filter = (interaction) => {
return interaction.user.id === discordId && ['previous', 'next', 'delete'].includes(interaction.customId);
};

const collector = pageEmbed.createMessageComponentCollector({ filter, time });

collector.on('collect', async (interaction) => {
if (interaction.customId === 'previous') {
page = page > 0 ? --page : embeds.length - 1;
} else if (interaction.customId === 'next') {
page = page + 1 < embeds.length ? ++page : 0;
} else if (interaction.customId === 'delete') {
await pageEmbed.delete();
return;
}

await interaction.deferUpdate();
await pageEmbed.edit({ embeds: [embeds[page]], components: [row] });
});

collector.on('end', async () => {
try {
embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
catch {
return;
}
});
}
const { ButtonBuilder, ButtonStyle, ActionRowBuilder } = require('discord.js');

async function menuButtons(discordId, message, time, embeds, startPage) {
let page = startPage;

const row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('previous')
.setLabel('Previous')
.setStyle(ButtonStyle.Primary)
.setEmoji('◀️'),
new ButtonBuilder()
.setCustomId('next')
.setLabel('Next')
.setStyle(ButtonStyle.Primary)
.setEmoji('▶️'),
new ButtonBuilder()
.setCustomId('delete')
.setLabel('Delete')
.setStyle(ButtonStyle.Danger)
.setEmoji('🗑️'),
);

const pageEmbed = await message.channel.send({ embeds: [embeds[page]], components: [row] });

const filter = (interaction) => {
return interaction.user.id === discordId && ['previous', 'next', 'delete'].includes(interaction.customId);
};

const collector = pageEmbed.createMessageComponentCollector({ filter, time });

collector.on('collect', async (interaction) => {
if (interaction.customId === 'previous') {
page = page > 0 ? --page : embeds.length - 1;
} else if (interaction.customId === 'next') {
page = page + 1 < embeds.length ? ++page : 0;
} else if (interaction.customId === 'delete') {
await pageEmbed.delete();
return;
}

await interaction.deferUpdate();
await pageEmbed.edit({ embeds: [embeds[page]], components: [row] });
});

collector.on('end', async () => {
try {
embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
catch {
return;
}
});
}
async function createEncEmbed(character, colour) {
const totalStats = character.attack + character.magattack + character.defense + character.magdefense + character.hp + character.speed;
const attachment = (`./CardImages/${character.image}`);

const imageEmbed = new EmbedBuilder();

if (colour) {
imageEmbed.setColor(0x00FF00);
} else {
imageEmbed.setColor(0xFF0000);
}

imageEmbed
.setTitle(`${character.element} ${character.name}`)
.setDescription(character.desc)
.setThumbnail(`attachment://${character.image}`)
.addFields(
{ name: "**Series: **", value: `${character.series}`, inline: false },
{ name: "**Stats: **", value: `Health: ${String(character.hp)}\nAttack: ${String(character.attack)}\nMagic Attack: ${String(character.magattack)}\nDefense: ${String(character.defense)}\nMagic Defense: ${String(character.magdefense)}\nSpeed: ${String(character.speed)}\nTotal Stats: ${String(totalStats)}`, inline: false }
);

return { embeds: [imageEmbed], files: [attachment] };
}
async function createEncEmbed(character, colour) {
const totalStats = character.attack + character.magattack + character.defense + character.magdefense + character.hp + character.speed;
const attachment = (`./CardImages/${character.image}`);

const imageEmbed = new EmbedBuilder();

if (colour) {
imageEmbed.setColor(0x00FF00);
} else {
imageEmbed.setColor(0xFF0000);
}

imageEmbed
.setTitle(`${character.element} ${character.name}`)
.setDescription(character.desc)
.setThumbnail(`attachment://${character.image}`)
.addFields(
{ name: "**Series: **", value: `${character.series}`, inline: false },
{ name: "**Stats: **", value: `Health: ${String(character.hp)}\nAttack: ${String(character.attack)}\nMagic Attack: ${String(character.magattack)}\nDefense: ${String(character.defense)}\nMagic Defense: ${String(character.magdefense)}\nSpeed: ${String(character.speed)}\nTotal Stats: ${String(totalStats)}`, inline: false }
);

return { embeds: [imageEmbed], files: [attachment] };
}
40 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 5/16/2023 in #djs-questions
Deleting messages with button action
hey so i know this is probably a really minor issue but i'm making an interactable embed with button interactions and im almost done but when i press a delete button i made, the embed is gone just as intended, but the bot crashes and gives me this error: Uncaught DiscordAPIError DiscordAPIError[10008]: Unknown Message at handleErrors (c:\Users\Moh\Desktop\clutter\Gacha-Bot\bot-14\Tater\node_modules@discordjs\rest\dist\index.js:640:13) at processTicksAndRejections (internal/process/task_queues:95:5) i suspect i can fix the code here
collector.on('end', async () => {
if (pageEmbed.deleted) {
return;
}

embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
collector.on('end', async () => {
if (pageEmbed.deleted) {
return;
}

embeds[page].setColor('#808080'); // Set color to gray
await pageEmbed.edit({ embeds: [embeds[page]], components: [] }); // Remove buttons when time is up
}
i wrote
if (pageEmbed.deleted) {
return;
}
if (pageEmbed.deleted) {
return;
}
intending that if its gone it should just return and do nothing, thats where im guessing the error is coming from anyway.
5 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 5/8/2023 in #djs-questions
EmbedBuilder troubles
23 replies
DIAdiscord.js - Imagine an app
Created by Xu Xiaolan on 5/8/2023 in #djs-questions
storing images for output
I'm making a bot rn and I'm using the string for message links to post images on like embeds and stuff. But I got a good feeling that that's not very efficient or ideal, what would be a better way to store and output images for a bot? If its of any relevancy I'm using sqlite for a database
8 replies